blob: 882e2c04d1110201abe282089ecf77aa99da64bf [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
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020011#include "test/testsupport/test_output.h"
ilnike264a9e2017-07-25 07:31:18 -070012
13#include <string.h>
14
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020015#include "rtc_base/file.h"
16#include "rtc_base/flags.h"
17#include "rtc_base/logging.h"
18#include "rtc_base/pathutils.h"
19#include "test/testsupport/fileutils.h"
ilnike264a9e2017-07-25 07:31:18 -070020
oprypin9b2f20c2017-08-29 05:51:57 -070021namespace {
22const std::string& DefaultOutputPath() {
23 static const std::string path = webrtc::test::OutputPath();
24 return path;
25}
26}
27
ilnike264a9e2017-07-25 07:31:18 -070028DEFINE_string(test_output_dir,
oprypin9b2f20c2017-08-29 05:51:57 -070029 DefaultOutputPath().c_str(),
ilnike264a9e2017-07-25 07:31:18 -070030 "The output folder where test output should be saved.");
31
32namespace webrtc {
33namespace test {
34
35bool GetTestOutputDir(std::string* out_dir) {
oprypin9b2f20c2017-08-29 05:51:57 -070036 if (strlen(FLAG_test_output_dir) == 0) {
ilnike264a9e2017-07-25 07:31:18 -070037 LOG(LS_WARNING) << "No test_out_dir defined.";
38 return false;
39 }
oprypin9b2f20c2017-08-29 05:51:57 -070040 *out_dir = FLAG_test_output_dir;
ilnike264a9e2017-07-25 07:31:18 -070041 return true;
42}
43
44bool WriteToTestOutput(const char* filename,
45 const uint8_t* buffer,
46 size_t length) {
oprypin9b2f20c2017-08-29 05:51:57 -070047 if (strlen(FLAG_test_output_dir) == 0) {
ilnike264a9e2017-07-25 07:31:18 -070048 LOG(LS_WARNING) << "No test_out_dir defined.";
49 return false;
50 }
51
52 if (filename == nullptr || strlen(filename) == 0) {
53 LOG(LS_WARNING) << "filename must be provided.";
54 return false;
55 }
56
57 rtc::File output =
oprypin9b2f20c2017-08-29 05:51:57 -070058 rtc::File::Create(rtc::Pathname(FLAG_test_output_dir, filename));
ilnike264a9e2017-07-25 07:31:18 -070059
60 return output.IsOpen() && output.Write(buffer, length) == length;
61}
62
63bool WriteToTestOutput(const char* filename, const std::string& content) {
64 return WriteToTestOutput(filename,
65 reinterpret_cast<const uint8_t*>(content.c_str()),
66 content.length());
67}
68
69} // namespace test
70} // namespace webrtc