diff --git a/packager/packager.gyp b/packager/packager.gyp index ab213c7fbe..038fe1cb7d 100644 --- a/packager/packager.gyp +++ b/packager/packager.gyp @@ -132,7 +132,6 @@ 'packager_test.cc', ], 'dependencies': [ - 'base/base.gyp:base', 'libpackager', 'testing/gmock.gyp:gmock', 'testing/gtest.gyp:gtest', diff --git a/packager/packager_test.cc b/packager/packager_test.cc index 1e5120cdb5..aa239b88dc 100644 --- a/packager/packager_test.cc +++ b/packager/packager_test.cc @@ -7,10 +7,6 @@ #include #include -#include "packager/base/files/file_util.h" -#include "packager/base/logging.h" -#include "packager/base/path_service.h" -#include "packager/base/strings/string_number_conversions.h" #include "packager/packager.h" using testing::_; @@ -24,29 +20,23 @@ using testing::WithArgs; namespace shaka { namespace { -const char kTestFile[] = "bear-640x360.mp4"; +const char kTestFile[] = "packager/media/test/data/bear-640x360.mp4"; const char kOutputVideo[] = "output_video.mp4"; const char kOutputVideoTemplate[] = "output_video_$Number$.m4s"; const char kOutputAudio[] = "output_audio.mp4"; const char kOutputMpd[] = "output.mpd"; const double kSegmentDurationInSeconds = 1.0; -const char kKeyIdHex[] = "e5007e6e9dcd5ac095202ed3758382cd"; -const char kKeyHex[] = "6fc96fe628a265b13aeddec0bc421f4d"; +const uint8_t kKeyId[] = { + 0xe5, 0x00, 0x7e, 0x6e, 0x9d, 0xcd, 0x5a, 0xc0, + 0x95, 0x20, 0x2e, 0xd3, 0x75, 0x83, 0x82, 0xcd, +}; +const uint8_t kKey[]{ + 0x6f, 0xc9, 0x6f, 0xe6, 0x28, 0xa2, 0x65, 0xb1, + 0x3a, 0xed, 0xde, 0xc0, 0xbc, 0x42, 0x1f, 0x4d, +}; const double kClearLeadInSeconds = 1.0; -std::string 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.AsUTF8Unsafe(); -} - } // namespace class PackagerTest : public ::testing::Test { @@ -54,21 +44,21 @@ class PackagerTest : public ::testing::Test { PackagerTest() {} void SetUp() override { - // Create a test directory for testing, will be deleted after test. - ASSERT_TRUE(base::CreateNewTempDirectory( - base::FilePath::FromUTF8Unsafe("packager_").value(), &test_directory_)); + FILE* f = fopen(kTestFile, "rb"); + if (!f) { + FAIL() << "The test is expected to run from packager repository root."; + return; + } + fclose(f); } - void TearDown() override { base::DeleteFile(test_directory_, true); } - std::string GetFullPath(const std::string& file_name) { - return test_directory_.Append(base::FilePath::FromUTF8Unsafe(file_name)) - .AsUTF8Unsafe(); + return test_directory_ + file_name; } PackagingParams SetupPackagingParams() { PackagingParams packaging_params; - packaging_params.temp_dir = test_directory_.AsUTF8Unsafe(); + packaging_params.temp_dir = test_directory_; packaging_params.chunking_params.segment_duration_in_seconds = kSegmentDurationInSeconds; packaging_params.mpd_params.mpd_output = GetFullPath(kOutputMpd); @@ -76,11 +66,10 @@ class PackagerTest : public ::testing::Test { packaging_params.encryption_params.clear_lead_in_seconds = kClearLeadInSeconds; packaging_params.encryption_params.key_provider = KeyProvider::kRawKey; - CHECK(base::HexStringToBytes( - kKeyIdHex, - &packaging_params.encryption_params.raw_key.key_map[""].key_id)); - CHECK(base::HexStringToBytes( - kKeyHex, &packaging_params.encryption_params.raw_key.key_map[""].key)); + packaging_params.encryption_params.raw_key.key_map[""].key_id.assign( + std::begin(kKeyId), std::end(kKeyId)); + packaging_params.encryption_params.raw_key.key_map[""].key.assign( + std::begin(kKey), std::end(kKey)); return packaging_params; } @@ -88,12 +77,12 @@ class PackagerTest : public ::testing::Test { std::vector stream_descriptors; StreamDescriptor stream_descriptor; - stream_descriptor.input = GetTestDataFilePath(kTestFile); + stream_descriptor.input = kTestFile; stream_descriptor.stream_selector = "video"; stream_descriptor.output = GetFullPath(kOutputVideo); stream_descriptors.push_back(stream_descriptor); - stream_descriptor.input = GetTestDataFilePath(kTestFile); + stream_descriptor.input = kTestFile; stream_descriptor.stream_selector = "audio"; stream_descriptor.output = GetFullPath(kOutputAudio); stream_descriptors.push_back(stream_descriptor); @@ -102,7 +91,8 @@ class PackagerTest : public ::testing::Test { } protected: - base::FilePath test_directory_; + // Use memory file for testing. + std::string test_directory_ = "memory://test/"; }; TEST_F(PackagerTest, Version) { @@ -127,13 +117,13 @@ TEST_F(PackagerTest, MixingSegmentTemplateAndSingleSegment) { std::vector stream_descriptors; StreamDescriptor stream_descriptor; - stream_descriptor.input = GetTestDataFilePath(kTestFile); + stream_descriptor.input = kTestFile; stream_descriptor.stream_selector = "video"; stream_descriptor.output = GetFullPath(kOutputVideo); stream_descriptor.segment_template = GetFullPath(kOutputVideoTemplate); stream_descriptors.push_back(stream_descriptor); - stream_descriptor.input = GetTestDataFilePath(kTestFile); + stream_descriptor.input = kTestFile; stream_descriptor.stream_selector = "audio"; stream_descriptor.output = GetFullPath(kOutputAudio); stream_descriptor.segment_template.clear(); @@ -192,9 +182,8 @@ TEST_F(PackagerTest, ReadFromBuffer) { packaging_params.buffer_callback_params.read_func = mock_read_func.AsStdFunction(); - const std::string file_name = GetTestDataFilePath(kTestFile); - FILE* file_ptr = - base::OpenFile(base::FilePath::FromUTF8Unsafe(file_name), "rb"); + const std::string file_name = kTestFile; + FILE* file_ptr = fopen(file_name.c_str(), "rb"); ASSERT_TRUE(file_ptr); EXPECT_CALL(mock_read_func, Call(StrEq(file_name), _, _)) .WillRepeatedly( @@ -207,7 +196,7 @@ TEST_F(PackagerTest, ReadFromBuffer) { packager.Initialize(packaging_params, SetupStreamDescriptors())); ASSERT_EQ(Status::OK, packager.Run()); - base::CloseFile(file_ptr); + fclose(file_ptr); } TEST_F(PackagerTest, ReadFromBufferFailed) {