From c73bfadd0ebb7eff3775ffb3376338faf34e5f5c Mon Sep 17 00:00:00 2001 From: Kongqun Yang Date: Thu, 9 Jan 2014 15:50:18 -0800 Subject: [PATCH] Move test utilities in media/base to media/test. Also clean up test_data_util.cc. Change-Id: Ic6038e072939d55fad7cc739b53ab9888b4251c1 --- media/base/container_names_unittest.cc | 5 ++-- media/mp4/mp4_media_parser_unittest.cc | 10 +------ media/test/packager_test.cc | 2 +- .../run_tests_with_atexit_manager.cc | 0 media/{base => test}/test_data_util.cc | 26 +++---------------- media/{base => test}/test_data_util.h | 13 +++------- packager.gyp | 7 +++-- 7 files changed, 16 insertions(+), 47 deletions(-) rename media/{base => test}/run_tests_with_atexit_manager.cc (100%) rename media/{base => test}/test_data_util.cc (50%) rename media/{base => test}/test_data_util.h (55%) diff --git a/media/base/container_names_unittest.cc b/media/base/container_names_unittest.cc index acfead8b5f..4f78d6093b 100644 --- a/media/base/container_names_unittest.cc +++ b/media/base/container_names_unittest.cc @@ -2,9 +2,10 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "base/file_util.h" #include "media/base/container_names.h" -#include "media/base/test_data_util.h" + +#include "base/file_util.h" +#include "media/test/test_data_util.h" #include "testing/gtest/include/gtest/gtest.h" namespace media { diff --git a/media/mp4/mp4_media_parser_unittest.cc b/media/mp4/mp4_media_parser_unittest.cc index 3124624747..b05bd3c8d0 100644 --- a/media/mp4/mp4_media_parser_unittest.cc +++ b/media/mp4/mp4_media_parser_unittest.cc @@ -4,18 +4,10 @@ #include "media/mp4/mp4_media_parser.h" -#include -#include - #include "base/bind.h" -#include "base/bind_helpers.h" #include "base/logging.h" -#include "base/memory/ref_counted.h" -#include "base/time/time.h" #include "media/base/media_sample.h" -#include "media/base/stream_info.h" -#include "media/base/test_data_util.h" -#include "media/mp4/es_descriptor.h" +#include "media/test/test_data_util.h" #include "testing/gtest/include/gtest/gtest.h" namespace media { diff --git a/media/test/packager_test.cc b/media/test/packager_test.cc index 68b079a4a7..da7ad896f5 100644 --- a/media/test/packager_test.cc +++ b/media/test/packager_test.cc @@ -11,8 +11,8 @@ #include "media/base/muxer_options.h" #include "media/base/status_test_util.h" #include "media/base/stream_info.h" -#include "media/base/test_data_util.h" #include "media/mp4/mp4_muxer.h" +#include "media/test/test_data_util.h" #include "testing/gtest/include/gtest/gtest.h" using ::testing::Combine; diff --git a/media/base/run_tests_with_atexit_manager.cc b/media/test/run_tests_with_atexit_manager.cc similarity index 100% rename from media/base/run_tests_with_atexit_manager.cc rename to media/test/run_tests_with_atexit_manager.cc diff --git a/media/base/test_data_util.cc b/media/test/test_data_util.cc similarity index 50% rename from media/base/test_data_util.cc rename to media/test/test_data_util.cc index fba3f75e30..9180c229f0 100644 --- a/media/base/test_data_util.cc +++ b/media/test/test_data_util.cc @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "media/base/test_data_util.h" +#include "media/test/test_data_util.h" #include "base/file_util.h" #include "base/logging.h" @@ -22,27 +22,9 @@ base::FilePath GetTestDataFilePath(const std::string& name) { } std::vector ReadTestDataFile(const std::string& name) { - base::FilePath file_path; - CHECK(PathService::Get(base::DIR_SOURCE_ROOT, &file_path)); - - file_path = file_path.Append(FILE_PATH_LITERAL("media")) - .Append(FILE_PATH_LITERAL("test")) - .Append(FILE_PATH_LITERAL("data")) - .AppendASCII(name); - - int64 tmp = 0; - CHECK(file_util::GetFileSize(file_path, &tmp)) - << "Failed to get file size for '" << name << "'"; - - int file_size = static_cast(tmp); - std::vector buffer(file_size); - - CHECK_EQ(file_size, - file_util::ReadFile( - file_path, reinterpret_cast(&buffer[0]), file_size)) - << "Failed to read '" << name << "'"; - - return buffer; + std::string buffer; + CHECK(file_util::ReadFileToString(GetTestDataFilePath(name), &buffer)); + return std::vector(buffer.begin(), buffer.end()); } } // namespace media diff --git a/media/base/test_data_util.h b/media/test/test_data_util.h similarity index 55% rename from media/base/test_data_util.h rename to media/test/test_data_util.h index cbf280f3f3..7b998ac232 100644 --- a/media/base/test_data_util.h +++ b/media/test/test_data_util.h @@ -2,8 +2,8 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#ifndef MEDIA_BASE_TEST_DATA_UTIL_H_ -#define MEDIA_BASE_TEST_DATA_UTIL_H_ +#ifndef MEDIA_TEST_TEST_DATA_UTIL_H_ +#define MEDIA_TEST_TEST_DATA_UTIL_H_ #include @@ -15,14 +15,9 @@ namespace media { // Returns a file path for a file in the media/test/data directory. base::FilePath GetTestDataFilePath(const std::string& name); -// Reads a test file from media/test/data directory and stores it in -// a DecoderBuffer. Use DecoderBuffer vs DataBuffer to ensure no matter -// what a test does, it's safe to use FFmpeg methods. -// -// |name| - The name of the file. -// |buffer| - The contents of the file. +// Reads a test file from media/test/data directory and returns its content. std::vector ReadTestDataFile(const std::string& name); } // namespace media -#endif // MEDIA_BASE_TEST_DATA_UTIL_H_ +#endif // MEDIA_TEST_TEST_DATA_UTIL_H_ diff --git a/packager.gyp b/packager.gyp index 1710b50a2b..64399ab384 100644 --- a/packager.gyp +++ b/packager.gyp @@ -64,10 +64,9 @@ 'target_name': 'media_test_support', 'type': 'static_library', 'sources': [ - # TODO(kqyang): move these files to test directory. - 'media/base/run_tests_with_atexit_manager.cc', - 'media/base/test_data_util.cc', - 'media/base/test_data_util.h', + 'media/test/run_tests_with_atexit_manager.cc', + 'media/test/test_data_util.cc', + 'media/test/test_data_util.h', ], 'dependencies': [ 'base/base.gyp:base',