Remove base dependency from packager_test.cc

So that packager library is used in the same way as how it is used
in real world.

Change-Id: I38a59f4b1153edd048f078df4447cd9c0464caa5
This commit is contained in:
KongQun Yang 2018-08-01 14:50:12 -07:00
parent ca810e06d5
commit 64c3b4c558
2 changed files with 30 additions and 42 deletions

View File

@ -132,7 +132,6 @@
'packager_test.cc', 'packager_test.cc',
], ],
'dependencies': [ 'dependencies': [
'base/base.gyp:base',
'libpackager', 'libpackager',
'testing/gmock.gyp:gmock', 'testing/gmock.gyp:gmock',
'testing/gtest.gyp:gtest', 'testing/gtest.gyp:gtest',

View File

@ -7,10 +7,6 @@
#include <gmock/gmock.h> #include <gmock/gmock.h>
#include <gtest/gtest.h> #include <gtest/gtest.h>
#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" #include "packager/packager.h"
using testing::_; using testing::_;
@ -24,29 +20,23 @@ using testing::WithArgs;
namespace shaka { namespace shaka {
namespace { 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 kOutputVideo[] = "output_video.mp4";
const char kOutputVideoTemplate[] = "output_video_$Number$.m4s"; const char kOutputVideoTemplate[] = "output_video_$Number$.m4s";
const char kOutputAudio[] = "output_audio.mp4"; const char kOutputAudio[] = "output_audio.mp4";
const char kOutputMpd[] = "output.mpd"; const char kOutputMpd[] = "output.mpd";
const double kSegmentDurationInSeconds = 1.0; const double kSegmentDurationInSeconds = 1.0;
const char kKeyIdHex[] = "e5007e6e9dcd5ac095202ed3758382cd"; const uint8_t kKeyId[] = {
const char kKeyHex[] = "6fc96fe628a265b13aeddec0bc421f4d"; 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; 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 } // namespace
class PackagerTest : public ::testing::Test { class PackagerTest : public ::testing::Test {
@ -54,21 +44,21 @@ class PackagerTest : public ::testing::Test {
PackagerTest() {} PackagerTest() {}
void SetUp() override { void SetUp() override {
// Create a test directory for testing, will be deleted after test. FILE* f = fopen(kTestFile, "rb");
ASSERT_TRUE(base::CreateNewTempDirectory( if (!f) {
base::FilePath::FromUTF8Unsafe("packager_").value(), &test_directory_)); 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) { std::string GetFullPath(const std::string& file_name) {
return test_directory_.Append(base::FilePath::FromUTF8Unsafe(file_name)) return test_directory_ + file_name;
.AsUTF8Unsafe();
} }
PackagingParams SetupPackagingParams() { PackagingParams SetupPackagingParams() {
PackagingParams packaging_params; PackagingParams packaging_params;
packaging_params.temp_dir = test_directory_.AsUTF8Unsafe(); packaging_params.temp_dir = test_directory_;
packaging_params.chunking_params.segment_duration_in_seconds = packaging_params.chunking_params.segment_duration_in_seconds =
kSegmentDurationInSeconds; kSegmentDurationInSeconds;
packaging_params.mpd_params.mpd_output = GetFullPath(kOutputMpd); 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 = packaging_params.encryption_params.clear_lead_in_seconds =
kClearLeadInSeconds; kClearLeadInSeconds;
packaging_params.encryption_params.key_provider = KeyProvider::kRawKey; packaging_params.encryption_params.key_provider = KeyProvider::kRawKey;
CHECK(base::HexStringToBytes( packaging_params.encryption_params.raw_key.key_map[""].key_id.assign(
kKeyIdHex, std::begin(kKeyId), std::end(kKeyId));
&packaging_params.encryption_params.raw_key.key_map[""].key_id)); packaging_params.encryption_params.raw_key.key_map[""].key.assign(
CHECK(base::HexStringToBytes( std::begin(kKey), std::end(kKey));
kKeyHex, &packaging_params.encryption_params.raw_key.key_map[""].key));
return packaging_params; return packaging_params;
} }
@ -88,12 +77,12 @@ class PackagerTest : public ::testing::Test {
std::vector<StreamDescriptor> stream_descriptors; std::vector<StreamDescriptor> stream_descriptors;
StreamDescriptor stream_descriptor; StreamDescriptor stream_descriptor;
stream_descriptor.input = GetTestDataFilePath(kTestFile); stream_descriptor.input = kTestFile;
stream_descriptor.stream_selector = "video"; stream_descriptor.stream_selector = "video";
stream_descriptor.output = GetFullPath(kOutputVideo); stream_descriptor.output = GetFullPath(kOutputVideo);
stream_descriptors.push_back(stream_descriptor); stream_descriptors.push_back(stream_descriptor);
stream_descriptor.input = GetTestDataFilePath(kTestFile); stream_descriptor.input = kTestFile;
stream_descriptor.stream_selector = "audio"; stream_descriptor.stream_selector = "audio";
stream_descriptor.output = GetFullPath(kOutputAudio); stream_descriptor.output = GetFullPath(kOutputAudio);
stream_descriptors.push_back(stream_descriptor); stream_descriptors.push_back(stream_descriptor);
@ -102,7 +91,8 @@ class PackagerTest : public ::testing::Test {
} }
protected: protected:
base::FilePath test_directory_; // Use memory file for testing.
std::string test_directory_ = "memory://test/";
}; };
TEST_F(PackagerTest, Version) { TEST_F(PackagerTest, Version) {
@ -127,13 +117,13 @@ TEST_F(PackagerTest, MixingSegmentTemplateAndSingleSegment) {
std::vector<StreamDescriptor> stream_descriptors; std::vector<StreamDescriptor> stream_descriptors;
StreamDescriptor stream_descriptor; StreamDescriptor stream_descriptor;
stream_descriptor.input = GetTestDataFilePath(kTestFile); stream_descriptor.input = kTestFile;
stream_descriptor.stream_selector = "video"; stream_descriptor.stream_selector = "video";
stream_descriptor.output = GetFullPath(kOutputVideo); stream_descriptor.output = GetFullPath(kOutputVideo);
stream_descriptor.segment_template = GetFullPath(kOutputVideoTemplate); stream_descriptor.segment_template = GetFullPath(kOutputVideoTemplate);
stream_descriptors.push_back(stream_descriptor); stream_descriptors.push_back(stream_descriptor);
stream_descriptor.input = GetTestDataFilePath(kTestFile); stream_descriptor.input = kTestFile;
stream_descriptor.stream_selector = "audio"; stream_descriptor.stream_selector = "audio";
stream_descriptor.output = GetFullPath(kOutputAudio); stream_descriptor.output = GetFullPath(kOutputAudio);
stream_descriptor.segment_template.clear(); stream_descriptor.segment_template.clear();
@ -192,9 +182,8 @@ TEST_F(PackagerTest, ReadFromBuffer) {
packaging_params.buffer_callback_params.read_func = packaging_params.buffer_callback_params.read_func =
mock_read_func.AsStdFunction(); mock_read_func.AsStdFunction();
const std::string file_name = GetTestDataFilePath(kTestFile); const std::string file_name = kTestFile;
FILE* file_ptr = FILE* file_ptr = fopen(file_name.c_str(), "rb");
base::OpenFile(base::FilePath::FromUTF8Unsafe(file_name), "rb");
ASSERT_TRUE(file_ptr); ASSERT_TRUE(file_ptr);
EXPECT_CALL(mock_read_func, Call(StrEq(file_name), _, _)) EXPECT_CALL(mock_read_func, Call(StrEq(file_name), _, _))
.WillRepeatedly( .WillRepeatedly(
@ -207,7 +196,7 @@ TEST_F(PackagerTest, ReadFromBuffer) {
packager.Initialize(packaging_params, SetupStreamDescriptors())); packager.Initialize(packaging_params, SetupStreamDescriptors()));
ASSERT_EQ(Status::OK, packager.Run()); ASSERT_EQ(Status::OK, packager.Run());
base::CloseFile(file_ptr); fclose(file_ptr);
} }
TEST_F(PackagerTest, ReadFromBufferFailed) { TEST_F(PackagerTest, ReadFromBufferFailed) {