blob: 9bb1847199b032ade339eb4545c2de7c7f69d2a7 [file] [log] [blame]
ilnike264a9e2017-07-25 07:31:18 -07001/*
2 * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved.
3 *
4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
10
11#include "webrtc/test/testsupport/test_output.h"
12
13#include <string.h>
14
ilnik26e5cbd2017-08-18 09:00:04 -070015#include "webrtc/rtc_base/flags.h"
ilnike264a9e2017-07-25 07:31:18 -070016#include "webrtc/rtc_base/file.h"
17#include "webrtc/rtc_base/logging.h"
18#include "webrtc/rtc_base/pathutils.h"
19#include "webrtc/test/testsupport/fileutils.h"
20
ilnik26e5cbd2017-08-18 09:00:04 -070021namespace {
22const std::string kDefaultOutputPath = webrtc::test::OutputPath();
23}
24
ilnike264a9e2017-07-25 07:31:18 -070025DEFINE_string(test_output_dir,
ilnik26e5cbd2017-08-18 09:00:04 -070026 kDefaultOutputPath.c_str(),
ilnike264a9e2017-07-25 07:31:18 -070027 "The output folder where test output should be saved.");
28
29namespace webrtc {
30namespace test {
31
32bool GetTestOutputDir(std::string* out_dir) {
ilnik26e5cbd2017-08-18 09:00:04 -070033 if (strlen(FLAG_test_output_dir) == 0) {
ilnike264a9e2017-07-25 07:31:18 -070034 LOG(LS_WARNING) << "No test_out_dir defined.";
35 return false;
36 }
ilnik26e5cbd2017-08-18 09:00:04 -070037 *out_dir = FLAG_test_output_dir;
ilnike264a9e2017-07-25 07:31:18 -070038 return true;
39}
40
41bool WriteToTestOutput(const char* filename,
42 const uint8_t* buffer,
43 size_t length) {
ilnik26e5cbd2017-08-18 09:00:04 -070044 if (strlen(FLAG_test_output_dir) == 0) {
ilnike264a9e2017-07-25 07:31:18 -070045 LOG(LS_WARNING) << "No test_out_dir defined.";
46 return false;
47 }
48
49 if (filename == nullptr || strlen(filename) == 0) {
50 LOG(LS_WARNING) << "filename must be provided.";
51 return false;
52 }
53
54 rtc::File output =
ilnik26e5cbd2017-08-18 09:00:04 -070055 rtc::File::Create(rtc::Pathname(FLAG_test_output_dir, filename));
ilnike264a9e2017-07-25 07:31:18 -070056
57 return output.IsOpen() && output.Write(buffer, length) == length;
58}
59
60bool WriteToTestOutput(const char* filename, const std::string& content) {
61 return WriteToTestOutput(filename,
62 reinterpret_cast<const uint8_t*>(content.c_str()),
63 content.length());
64}
65
66} // namespace test
67} // namespace webrtc