Rename isolated_output to test_output and add a method to get the test_output directory.

BUG=none

TBR=kjellander@webrtc.org

patch from issue 2990533002 at patchset 1 (http://crrev.com/2990533002#ps1)
Already lgtm'ed in original issue. This only fixes trivial compilation errors.

Review-Url: https://codereview.webrtc.org/2989613002
Cr-Commit-Position: refs/heads/master@{#19133}
This commit is contained in:
ilnik 2017-07-25 07:31:18 -07:00 committed by Commit Bot
parent d5e3d0f958
commit e264a9ee9c
4 changed files with 49 additions and 35 deletions

View File

@ -235,11 +235,11 @@ if (!build_with_chromium) {
}
}
rtc_source_set("test_support_isolated_output") {
rtc_source_set("test_support_test_output") {
testonly = true
sources = [
"testsupport/isolated_output.cc",
"testsupport/isolated_output.h",
"testsupport/test_output.cc",
"testsupport/test_output.h",
]
deps = [
":fileutils",
@ -286,10 +286,10 @@ if (!build_with_chromium) {
"rtp_file_reader_unittest.cc",
"rtp_file_writer_unittest.cc",
"testsupport/always_passing_unittest.cc",
"testsupport/isolated_output_unittest.cc",
"testsupport/metrics/video_metrics_unittest.cc",
"testsupport/packet_reader_unittest.cc",
"testsupport/perf_test_unittest.cc",
"testsupport/test_output_unittest.cc",
"testsupport/y4m_frame_writer_unittest.cc",
"testsupport/yuv_frame_reader_unittest.cc",
"testsupport/yuv_frame_writer_unittest.cc",
@ -323,7 +323,7 @@ if (!build_with_chromium) {
":fileutils_unittests",
":test_common",
":test_main",
":test_support_isolated_output",
":test_support_test_output",
":video_test_common",
":video_test_support",
"../modules/video_capture",

View File

@ -8,7 +8,7 @@
* be found in the AUTHORS file in the root of the source tree.
*/
#include "webrtc/test/testsupport/isolated_output.h"
#include "webrtc/test/testsupport/test_output.h"
#include <string.h>
@ -18,17 +18,27 @@
#include "webrtc/rtc_base/pathutils.h"
#include "webrtc/test/testsupport/fileutils.h"
DEFINE_string(isolated_out_dir, webrtc::test::OutputPath(),
"The isolated output folder provided by swarming test framework.");
DEFINE_string(test_output_dir,
webrtc::test::OutputPath(),
"The output folder where test output should be saved.");
namespace webrtc {
namespace test {
bool WriteIsolatedOutput(const char* filename,
const uint8_t* buffer,
size_t length) {
if (FLAGS_isolated_out_dir.empty()) {
LOG(LS_WARNING) << "No isolated_out_dir defined.";
bool GetTestOutputDir(std::string* out_dir) {
if (FLAGS_test_output_dir.empty()) {
LOG(LS_WARNING) << "No test_out_dir defined.";
return false;
}
*out_dir = FLAGS_test_output_dir;
return true;
}
bool WriteToTestOutput(const char* filename,
const uint8_t* buffer,
size_t length) {
if (FLAGS_test_output_dir.empty()) {
LOG(LS_WARNING) << "No test_out_dir defined.";
return false;
}
@ -38,15 +48,15 @@ bool WriteIsolatedOutput(const char* filename,
}
rtc::File output =
rtc::File::Create(rtc::Pathname(FLAGS_isolated_out_dir, filename));
rtc::File::Create(rtc::Pathname(FLAGS_test_output_dir, filename));
return output.IsOpen() && output.Write(buffer, length) == length;
}
bool WriteIsolatedOutput(const char* filename, const std::string& content) {
return WriteIsolatedOutput(filename,
reinterpret_cast<const uint8_t*>(content.c_str()),
content.length());
bool WriteToTestOutput(const char* filename, const std::string& content) {
return WriteToTestOutput(filename,
reinterpret_cast<const uint8_t*>(content.c_str()),
content.length());
}
} // namespace test

View File

@ -8,8 +8,8 @@
* be found in the AUTHORS file in the root of the source tree.
*/
#ifndef WEBRTC_TEST_TESTSUPPORT_ISOLATED_OUTPUT_H_
#define WEBRTC_TEST_TESTSUPPORT_ISOLATED_OUTPUT_H_
#ifndef WEBRTC_TEST_TESTSUPPORT_TEST_OUTPUT_H_
#define WEBRTC_TEST_TESTSUPPORT_TEST_OUTPUT_H_
#include <stdlib.h>
@ -18,18 +18,22 @@
namespace webrtc {
namespace test {
// If the test_output_dir flag is set, returns true and copies the location of
// the dir to |out_dir|. Otherwise, return false.
bool GetTestOutputDir(std::string* out_dir);
// Writes a |length| bytes array |buffer| to |filename| in isolated output
// directory defined by swarming. If the file is existing, content will be
// appended. Otherwise a new file will be created. This function returns false
// if isolated output directory has not been defined, or |filename| indicates an
// invalid or non-writable file, or underlying file system errors.
bool WriteIsolatedOutput(const char* filename,
const uint8_t* buffer,
size_t length);
bool WriteToTestOutput(const char* filename,
const uint8_t* buffer,
size_t length);
bool WriteIsolatedOutput(const char* filename, const std::string& content);
bool WriteToTestOutput(const char* filename, const std::string& content);
} // namespace test
} // namespace webrtc
#endif // WEBRTC_TEST_TESTSUPPORT_ISOLATED_OUTPUT_H_
#endif // WEBRTC_TEST_TESTSUPPORT_TEST_OUTPUT_H_

View File

@ -8,7 +8,7 @@
* be found in the AUTHORS file in the root of the source tree.
*/
#include "webrtc/test/testsupport/isolated_output.h"
#include "webrtc/test/testsupport/test_output.h"
#include <string.h>
@ -20,29 +20,29 @@
#include "webrtc/rtc_base/platform_file.h"
#include "webrtc/test/gtest.h"
DECLARE_string(isolated_out_dir);
DECLARE_string(test_output_dir);
namespace webrtc {
namespace test {
TEST(IsolatedOutputTest, ShouldRejectInvalidIsolatedOutDir) {
std::string backup = FLAGS_isolated_out_dir;
FLAGS_isolated_out_dir = "";
ASSERT_FALSE(WriteIsolatedOutput("a-file", "some-contents"));
FLAGS_isolated_out_dir = backup;
std::string backup = FLAGS_test_output_dir;
FLAGS_test_output_dir = "";
ASSERT_FALSE(WriteToTestOutput("a-file", "some-contents"));
FLAGS_test_output_dir = backup;
}
TEST(IsolatedOutputTest, ShouldRejectInvalidFileName) {
ASSERT_FALSE(WriteIsolatedOutput(nullptr, "some-contents"));
ASSERT_FALSE(WriteIsolatedOutput("", "some-contents"));
ASSERT_FALSE(WriteToTestOutput(nullptr, "some-contents"));
ASSERT_FALSE(WriteToTestOutput("", "some-contents"));
}
// Sets isolated_out_dir=<a-writable-path> to execute this test.
TEST(IsolatedOutputTest, ShouldBeAbleToWriteContent) {
const char* filename = "a-file";
const char* content = "some-contents";
if (WriteIsolatedOutput(filename, content)) {
rtc::Pathname out_file(FLAGS_isolated_out_dir, filename);
if (WriteToTestOutput(filename, content)) {
rtc::Pathname out_file(FLAGS_test_output_dir, filename);
rtc::File input = rtc::File::Open(out_file);
EXPECT_TRUE(input.IsOpen());
EXPECT_TRUE(input.Seek(0));