diff --git a/mpd/mpd.gyp b/mpd/mpd.gyp
index 533a21bd5f..41a80d1f81 100644
--- a/mpd/mpd.gyp
+++ b/mpd/mpd.gyp
@@ -52,16 +52,19 @@
},
{
'target_name': 'mpd_unittest',
- 'type': 'executable',
+ 'type': '<(gtest_target_type)',
'sources': [
'base/mpd_builder_unittest.cc',
'base/xml/xml_node_unittest.cc',
+ 'util/mpd_writer_unittest.cc',
],
'dependencies': [
'../base/base.gyp:base',
'../base/base.gyp:run_all_unittests',
+ '../packager.gyp:file',
'../testing/gtest.gyp:gtest',
'mpd_builder',
+ 'mpd_util',
],
},
{
diff --git a/mpd/test/data/audio_media_info1.txt b/mpd/test/data/audio_media_info1.txt
new file mode 100644
index 0000000000..35e2bdcc6a
--- /dev/null
+++ b/mpd/test/data/audio_media_info1.txt
@@ -0,0 +1,11 @@
+bandwidth: 400
+audio_info {
+ codec: "mp4a.40.2"
+ sampling_frequency: 44100
+ time_scale: 1200
+ num_channels: 2
+}
+reference_time_scale: 50
+container_type: 1
+media_file_name: "test_output_file_name_audio1.mp4"
+media_duration_seconds: 10.5
diff --git a/mpd/test/data/audio_media_info1_expected_mpd_output.txt b/mpd/test/data/audio_media_info1_expected_mpd_output.txt
new file mode 100644
index 0000000000..197e6121bc
--- /dev/null
+++ b/mpd/test/data/audio_media_info1_expected_mpd_output.txt
@@ -0,0 +1,12 @@
+
+
+
+
+
+
+ test_output_file_name_audio1.mp4
+
+
+
+
+
diff --git a/mpd/test/data/audio_media_info1_video_media_info1_expected_mpd_output.txt b/mpd/test/data/audio_media_info1_video_media_info1_expected_mpd_output.txt
new file mode 100644
index 0000000000..cc43fce9cc
--- /dev/null
+++ b/mpd/test/data/audio_media_info1_video_media_info1_expected_mpd_output.txt
@@ -0,0 +1,20 @@
+
+
+
+
+
+ test_output_file_name1.mp4
+
+
+
+
+
+
+
+
+ test_output_file_name_audio1.mp4
+
+
+
+
+
diff --git a/mpd/test/data/video_media_info1.txt b/mpd/test/data/video_media_info1.txt
new file mode 100644
index 0000000000..f8cf2ef12a
--- /dev/null
+++ b/mpd/test/data/video_media_info1.txt
@@ -0,0 +1,19 @@
+bandwidth: 7620
+video_info {
+ codec: "avc1.010101"
+ width: 720
+ height: 480
+ time_scale: 10
+}
+init_range {
+ begin: 0
+ end: 120
+}
+index_range {
+ begin: 121
+ end: 221
+}
+reference_time_scale: 1000
+container_type: 1
+media_file_name: "test_output_file_name1.mp4"
+media_duration_seconds: 10.5
diff --git a/mpd/test/data/video_media_info1_expected_mpd_output.txt b/mpd/test/data/video_media_info1_expected_mpd_output.txt
new file mode 100644
index 0000000000..aa2caa1e7d
--- /dev/null
+++ b/mpd/test/data/video_media_info1_expected_mpd_output.txt
@@ -0,0 +1,13 @@
+
+
+
+
+
+ test_output_file_name1.mp4
+
+
+
+
+
+
+
diff --git a/mpd/test/data/video_media_info1and2_expected_mpd_output.txt b/mpd/test/data/video_media_info1and2_expected_mpd_output.txt
new file mode 100644
index 0000000000..bfc185738f
--- /dev/null
+++ b/mpd/test/data/video_media_info1and2_expected_mpd_output.txt
@@ -0,0 +1,19 @@
+
+
+
+
+
+ test_output_file_name1.mp4
+
+
+
+
+
+ test_output_file_name2.mp4
+
+
+
+
+
+
+
diff --git a/mpd/test/data/video_media_info2.txt b/mpd/test/data/video_media_info2.txt
new file mode 100644
index 0000000000..11fe76c121
--- /dev/null
+++ b/mpd/test/data/video_media_info2.txt
@@ -0,0 +1,19 @@
+bandwidth: 5000
+video_info {
+ codec: "avc1.010101"
+ width: 480
+ height: 360
+ time_scale: 20
+}
+init_range {
+ begin: 0
+ end: 53
+}
+index_range {
+ begin: 54
+ end: 100
+}
+reference_time_scale: 50
+container_type: 1
+media_file_name: "test_output_file_name2.mp4"
+media_duration_seconds: 10.5
diff --git a/mpd/util/mpd_writer_unittest.cc b/mpd/util/mpd_writer_unittest.cc
new file mode 100644
index 0000000000..a93608214e
--- /dev/null
+++ b/mpd/util/mpd_writer_unittest.cc
@@ -0,0 +1,95 @@
+#include "base/file_util.h"
+#include "base/path_service.h"
+#include "mpd/util/mpd_writer.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+// TODO(rkuroiwa): Move schema check function in mpd_builder_unittest.cc to
+// another file so that this file can use it as well.
+namespace dash_packager {
+
+namespace {
+base::FilePath GetTestDataFilePath(const std::string& file_name) {
+ base::FilePath file_path;
+ CHECK(PathService::Get(base::DIR_SOURCE_ROOT, &file_path));
+
+ file_path = file_path.Append(FILE_PATH_LITERAL("mpd"))
+ .Append(FILE_PATH_LITERAL("test"))
+ .Append(FILE_PATH_LITERAL("data"))
+ .AppendASCII(file_name);
+ return file_path;
+}
+
+void ExpectToEqualExpectedOutputFile(
+ const std::string& mpd_string,
+ const base::FilePath& expected_output_file) {
+ std::string expected_mpd;
+ ASSERT_TRUE(file_util::ReadFileToString(expected_output_file, &expected_mpd))
+ << "Failed to read: " << expected_output_file.value();
+ ASSERT_EQ(expected_mpd, mpd_string);
+}
+} // namespace
+
+TEST(MpdWriterTest, ReadMediaInfoFile_VideoMediaInfo) {
+ MpdWriter mpd_writer;
+ base::FilePath media_info_file = GetTestDataFilePath("video_media_info1.txt");
+
+ ASSERT_TRUE(mpd_writer.AddFile(media_info_file.value().c_str()));
+ std::string generated_mpd;
+ ASSERT_TRUE(mpd_writer.WriteMpdToString(&generated_mpd));
+
+ ASSERT_NO_FATAL_FAILURE(ExpectToEqualExpectedOutputFile(
+ generated_mpd,
+ GetTestDataFilePath("video_media_info1_expected_mpd_output.txt")));
+}
+
+TEST(MpdWriterTest, ReadMediaInfoFile_TwoVideoMediaInfo) {
+ MpdWriter mpd_writer;
+ base::FilePath media_info_file1 =
+ GetTestDataFilePath("video_media_info1.txt");
+ base::FilePath media_info_file2 =
+ GetTestDataFilePath("video_media_info2.txt");
+
+ ASSERT_TRUE(mpd_writer.AddFile(media_info_file1.value().c_str()));
+ ASSERT_TRUE(mpd_writer.AddFile(media_info_file2.value().c_str()));
+
+ std::string generated_mpd;
+ ASSERT_TRUE(mpd_writer.WriteMpdToString(&generated_mpd));
+
+ ASSERT_NO_FATAL_FAILURE(ExpectToEqualExpectedOutputFile(
+ generated_mpd,
+ GetTestDataFilePath("video_media_info1and2_expected_mpd_output.txt")));
+}
+
+TEST(MpdWriterTest, ReadMediaInfoFile_AudioMediaInfo) {
+ MpdWriter mpd_writer;
+ base::FilePath media_info_file = GetTestDataFilePath("audio_media_info1.txt");
+
+ ASSERT_TRUE(mpd_writer.AddFile(media_info_file.value().c_str()));
+ std::string generated_mpd;
+ ASSERT_TRUE(mpd_writer.WriteMpdToString(&generated_mpd));
+
+ ASSERT_NO_FATAL_FAILURE(ExpectToEqualExpectedOutputFile(
+ generated_mpd,
+ GetTestDataFilePath("audio_media_info1_expected_mpd_output.txt")));
+}
+
+TEST(MpdWriterTest, ReadMediaInfoFile_VideoAudioMediaInfo) {
+ MpdWriter mpd_writer;
+ base::FilePath audio_media_info =
+ GetTestDataFilePath("audio_media_info1.txt");
+ base::FilePath video_media_info =
+ GetTestDataFilePath("video_media_info1.txt");
+
+ ASSERT_TRUE(mpd_writer.AddFile(audio_media_info.value().c_str()));
+ ASSERT_TRUE(mpd_writer.AddFile(video_media_info.value().c_str()));
+
+ std::string generated_mpd;
+ ASSERT_TRUE(mpd_writer.WriteMpdToString(&generated_mpd));
+
+ ASSERT_NO_FATAL_FAILURE(ExpectToEqualExpectedOutputFile(
+ generated_mpd,
+ GetTestDataFilePath(
+ "audio_media_info1_video_media_info1_expected_mpd_output.txt")));
+}
+
+} // namespace dash_packager