diff --git a/packager/CMakeLists.txt b/packager/CMakeLists.txt index aa0d41bb70..e1ddee7628 100644 --- a/packager/CMakeLists.txt +++ b/packager/CMakeLists.txt @@ -41,6 +41,7 @@ endif() # Subdirectories with their own CMakeLists.txt, all of whose targets are built. add_subdirectory(file) add_subdirectory(kv_pairs) +add_subdirectory(media) add_subdirectory(status) add_subdirectory(third_party) add_subdirectory(tools) diff --git a/packager/media/CMakeLists.txt b/packager/media/CMakeLists.txt new file mode 100644 index 0000000000..2fd0c58bbf --- /dev/null +++ b/packager/media/CMakeLists.txt @@ -0,0 +1,8 @@ +# Copyright 2022 Google LLC. All rights reserved. +# +# Use of this source code is governed by a BSD-style +# license that can be found in the LICENSE file or at +# https://developers.google.com/open-source/licenses/bsd + +# Subdirectories with their own CMakeLists.txt, all of whose targets are built. +add_subdirectory(test) diff --git a/packager/media/test/CMakeLists.txt b/packager/media/test/CMakeLists.txt new file mode 100644 index 0000000000..41d890b437 --- /dev/null +++ b/packager/media/test/CMakeLists.txt @@ -0,0 +1,9 @@ +# Copyright 2022 Google LLC. All rights reserved. +# +# Use of this source code is governed by a BSD-style +# license that can be found in the LICENSE file or at +# https://developers.google.com/open-source/licenses/bsd + +add_library(test_data_util STATIC + test_data_util.cc) +target_link_libraries(test_data_util glog) diff --git a/packager/media/test/media_test.gyp b/packager/media/test/media_test.gyp deleted file mode 100644 index 79801524b2..0000000000 --- a/packager/media/test/media_test.gyp +++ /dev/null @@ -1,35 +0,0 @@ -# Copyright 2014 Google LLC. All rights reserved. -# -# Use of this source code is governed by a BSD-style -# license that can be found in the LICENSE file or at -# https://developers.google.com/open-source/licenses/bsd - -{ - 'variables': { - 'shaka_code': 1, - }, - 'targets': [ - { - 'target_name': 'run_tests_with_atexit_manager', - 'type': '<(component)', - 'sources': [ - 'run_tests_with_atexit_manager.cc', - ], - 'dependencies': [ - '../../testing/gtest.gyp:gtest', - ], - }, - { - 'target_name': 'media_test_support', - 'type': '<(component)', - 'sources': [ - 'test_data_util.cc', - 'test_data_util.h', - ], - 'dependencies': [ - '../../base/base.gyp:base', - 'run_tests_with_atexit_manager', - ], - }, - ], -} diff --git a/packager/media/test/run_tests_with_atexit_manager.cc b/packager/media/test/run_tests_with_atexit_manager.cc deleted file mode 100644 index a8ee2e62fd..0000000000 --- a/packager/media/test/run_tests_with_atexit_manager.cc +++ /dev/null @@ -1,29 +0,0 @@ -// Copyright 2014 Google LLC. All rights reserved. -// -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file or at -// https://developers.google.com/open-source/licenses/bsd - -#include - -#include "packager/base/at_exit.h" -#include "packager/base/command_line.h" -#include "packager/base/files/file_path.h" -#include "packager/base/logging.h" -#include "packager/base/path_service.h" - -int main(int argc, char **argv) { - base::AtExitManager exit; - - // Needed to enable VLOG/DVLOG through --vmodule or --v. - base::CommandLine::Init(argc, argv); - - // Set up logging. - logging::LoggingSettings log_settings; - log_settings.logging_dest = logging::LOG_TO_SYSTEM_DEBUG_LOG; - CHECK(logging::InitLogging(log_settings)); - - ::testing::InitGoogleTest(&argc, argv); - - return RUN_ALL_TESTS(); -} diff --git a/packager/media/test/test_data_util.cc b/packager/media/test/test_data_util.cc index ae029dd3bb..58e27b7b0e 100644 --- a/packager/media/test/test_data_util.cc +++ b/packager/media/test/test_data_util.cc @@ -4,41 +4,41 @@ #include "packager/media/test/test_data_util.h" -#include "packager/base/files/file_util.h" -#include "packager/base/logging.h" -#include "packager/base/path_service.h" +#include "glog/logging.h" namespace shaka { namespace media { -base::FilePath GetTestDataFilePath(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("packager")) - .Append(FILE_PATH_LITERAL("media")) - .Append(FILE_PATH_LITERAL("test")) - .Append(FILE_PATH_LITERAL("data")) - .AppendASCII(name); - return file_path; +// Returns a file path for a file in the media/test/data directory. +std::filesystem::path GetTestDataFilePath(const std::string& name) { + std::filesystem::path header_path(__FILE__); + return header_path.parent_path() / "data" / name; } -base::FilePath GetAppTestDataFilePath(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("packager")) - .Append(FILE_PATH_LITERAL("app")) - .Append(FILE_PATH_LITERAL("test")) - .Append(FILE_PATH_LITERAL("testdata")) - .AppendASCII(name); - return file_path; +// Returns a file path for a file in the media/app/test/testdata directory. +std::filesystem::path GetAppTestDataFilePath(const std::string& name) { + std::filesystem::path header_path(__FILE__); + return header_path.parent_path().parent_path() / "app" / "test" / "testdata" / + name; } +// Reads a test file from media/test/data directory and returns its content. std::vector ReadTestDataFile(const std::string& name) { - std::string buffer; - CHECK(base::ReadFileToString(GetTestDataFilePath(name), &buffer)); - return std::vector(buffer.begin(), buffer.end()); + std::filesystem::path path = GetTestDataFilePath(name); + + FILE* f = fopen(path.string().c_str(), "rb"); + if (!f) { + LOG(FATAL) << "Failed to read test data from " << path; + return std::vector(); + } + + std::vector data; + data.resize(std::filesystem::file_size(path)); + size_t size = fread(data.data(), 1, data.size(), f); + data.resize(size); + fclose(f); + + return data; } } // namespace media diff --git a/packager/media/test/test_data_util.h b/packager/media/test/test_data_util.h index 477a2bf3d4..90d6d1248d 100644 --- a/packager/media/test/test_data_util.h +++ b/packager/media/test/test_data_util.h @@ -7,18 +7,18 @@ #include +#include #include - -#include "packager/base/files/file_path.h" +#include namespace shaka { namespace media { // Returns a file path for a file in the media/test/data directory. -base::FilePath GetTestDataFilePath(const std::string& name); +std::filesystem::path GetTestDataFilePath(const std::string& name); // Returns a file path for a file in the media/app/test/testdata directory. -base::FilePath GetAppTestDataFilePath(const std::string& name); +std::filesystem::path GetAppTestDataFilePath(const std::string& name); // Reads a test file from media/test/data directory and returns its content. std::vector ReadTestDataFile(const std::string& name);