ilnik | e264a9e | 2017-07-25 07:31:18 -0700 | [diff] [blame] | 1 | /* |
| 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 | |
charujain | 3771ba3 | 2017-08-20 12:50:56 -0700 | [diff] [blame] | 15 | #include "gflags/gflags.h" |
ilnik | e264a9e | 2017-07-25 07:31:18 -0700 | [diff] [blame] | 16 | #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 | |
| 21 | DEFINE_string(test_output_dir, |
charujain | 3771ba3 | 2017-08-20 12:50:56 -0700 | [diff] [blame] | 22 | webrtc::test::OutputPath(), |
ilnik | e264a9e | 2017-07-25 07:31:18 -0700 | [diff] [blame] | 23 | "The output folder where test output should be saved."); |
| 24 | |
| 25 | namespace webrtc { |
| 26 | namespace test { |
| 27 | |
| 28 | bool GetTestOutputDir(std::string* out_dir) { |
charujain | 3771ba3 | 2017-08-20 12:50:56 -0700 | [diff] [blame] | 29 | if (FLAGS_test_output_dir.empty()) { |
ilnik | e264a9e | 2017-07-25 07:31:18 -0700 | [diff] [blame] | 30 | LOG(LS_WARNING) << "No test_out_dir defined."; |
| 31 | return false; |
| 32 | } |
charujain | 3771ba3 | 2017-08-20 12:50:56 -0700 | [diff] [blame] | 33 | *out_dir = FLAGS_test_output_dir; |
ilnik | e264a9e | 2017-07-25 07:31:18 -0700 | [diff] [blame] | 34 | return true; |
| 35 | } |
| 36 | |
| 37 | bool WriteToTestOutput(const char* filename, |
| 38 | const uint8_t* buffer, |
| 39 | size_t length) { |
charujain | 3771ba3 | 2017-08-20 12:50:56 -0700 | [diff] [blame] | 40 | if (FLAGS_test_output_dir.empty()) { |
ilnik | e264a9e | 2017-07-25 07:31:18 -0700 | [diff] [blame] | 41 | LOG(LS_WARNING) << "No test_out_dir defined."; |
| 42 | return false; |
| 43 | } |
| 44 | |
| 45 | if (filename == nullptr || strlen(filename) == 0) { |
| 46 | LOG(LS_WARNING) << "filename must be provided."; |
| 47 | return false; |
| 48 | } |
| 49 | |
| 50 | rtc::File output = |
charujain | 3771ba3 | 2017-08-20 12:50:56 -0700 | [diff] [blame] | 51 | rtc::File::Create(rtc::Pathname(FLAGS_test_output_dir, filename)); |
ilnik | e264a9e | 2017-07-25 07:31:18 -0700 | [diff] [blame] | 52 | |
| 53 | return output.IsOpen() && output.Write(buffer, length) == length; |
| 54 | } |
| 55 | |
| 56 | bool WriteToTestOutput(const char* filename, const std::string& content) { |
| 57 | return WriteToTestOutput(filename, |
| 58 | reinterpret_cast<const uint8_t*>(content.c_str()), |
| 59 | content.length()); |
| 60 | } |
| 61 | |
| 62 | } // namespace test |
| 63 | } // namespace webrtc |