2023-12-01 17:32:19 +00:00
|
|
|
// Copyright 2014 Google LLC. All rights reserved.
|
2014-02-14 23:21:05 +00:00
|
|
|
//
|
|
|
|
// 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
|
|
|
|
|
2023-12-01 17:32:19 +00:00
|
|
|
#include <packager/mpd/util/mpd_writer.h>
|
|
|
|
|
|
|
|
#include <filesystem>
|
|
|
|
|
2015-09-14 19:53:32 +00:00
|
|
|
#include <gmock/gmock.h>
|
2014-08-21 22:40:44 +00:00
|
|
|
#include <gtest/gtest.h>
|
|
|
|
|
2023-12-01 17:32:19 +00:00
|
|
|
#include <packager/file/file_test_util.h>
|
|
|
|
#include <packager/mpd/base/mock_mpd_notifier.h>
|
|
|
|
#include <packager/mpd/base/mpd_options.h>
|
|
|
|
#include <packager/mpd/test/mpd_builder_test_helper.h>
|
2014-01-28 23:06:58 +00:00
|
|
|
|
2016-05-20 21:19:33 +00:00
|
|
|
namespace shaka {
|
2014-01-28 23:06:58 +00:00
|
|
|
|
2015-09-14 19:53:32 +00:00
|
|
|
using ::testing::_;
|
|
|
|
using ::testing::Invoke;
|
|
|
|
using ::testing::Return;
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
class TestMpdNotifierFactory : public MpdNotifierFactory {
|
|
|
|
public:
|
|
|
|
TestMpdNotifierFactory() {}
|
2015-07-22 23:40:45 +00:00
|
|
|
~TestMpdNotifierFactory() override {}
|
2015-09-14 19:53:32 +00:00
|
|
|
|
|
|
|
// So sad that this method cannot be mocked (gmock errors at compile time).
|
|
|
|
// Also (probably) this version of gmock does not support returning
|
2016-08-17 17:41:40 +00:00
|
|
|
// std::unique_ptr.
|
2015-09-14 19:53:32 +00:00
|
|
|
// For now we only need to return MockMpdNotifier() with these set of
|
|
|
|
// expectations for all the tests.
|
2017-07-27 18:49:50 +00:00
|
|
|
std::unique_ptr<MpdNotifier> Create(const MpdOptions& mpd_options) override {
|
|
|
|
EXPECT_EQ(expected_base_urls_, mpd_options.mpd_params.base_urls);
|
2015-09-14 19:53:32 +00:00
|
|
|
|
2016-08-17 17:41:40 +00:00
|
|
|
std::unique_ptr<MockMpdNotifier> mock_notifier(
|
2016-12-21 23:28:56 +00:00
|
|
|
new MockMpdNotifier(mpd_options));
|
2015-09-14 19:53:32 +00:00
|
|
|
|
|
|
|
EXPECT_CALL(*mock_notifier, Init()).WillOnce(Return(true));
|
|
|
|
EXPECT_CALL(*mock_notifier, NotifyNewContainer(_, _))
|
|
|
|
.Times(2)
|
|
|
|
.WillRepeatedly(Return(true));
|
|
|
|
EXPECT_CALL(*mock_notifier, Flush()).WillOnce(Return(true));
|
2023-12-01 17:32:19 +00:00
|
|
|
return mock_notifier;
|
2015-09-14 19:53:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void SetExpectedBaseUrls(const std::vector<std::string>& base_urls) {
|
|
|
|
expected_base_urls_ = base_urls;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::vector<std::string> expected_base_urls_;
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
|
|
|
class MpdWriterTest : public ::testing::Test {
|
|
|
|
protected:
|
|
|
|
// Note that MpdWriter::SetMpdNotifierFactoryForTest() is not called in SetUp.
|
|
|
|
// Set expectations in the test and call it.
|
2015-07-22 23:40:45 +00:00
|
|
|
void SetUp() override {
|
2015-09-14 19:53:32 +00:00
|
|
|
notifier_factory_.reset(new TestMpdNotifierFactory());
|
|
|
|
}
|
|
|
|
|
|
|
|
void SetMpdNotifierFactoryForTest() {
|
2016-08-17 17:41:40 +00:00
|
|
|
mpd_writer_.SetMpdNotifierFactoryForTest(std::move(notifier_factory_));
|
2015-09-14 19:53:32 +00:00
|
|
|
}
|
|
|
|
|
2016-08-17 17:41:40 +00:00
|
|
|
std::unique_ptr<TestMpdNotifierFactory> notifier_factory_;
|
2015-09-14 19:53:32 +00:00
|
|
|
MpdWriter mpd_writer_;
|
|
|
|
};
|
|
|
|
|
|
|
|
// Verify that writing mpd to a file works.
|
|
|
|
// Also check that base URLs are passed correctly.
|
|
|
|
TEST_F(MpdWriterTest, WriteMpdToFile) {
|
|
|
|
const char kBaseUrl1[] = "http://cdn1.mydomain.com/";
|
|
|
|
const char kBaseUrl2[] = "http://cdn2.mydomain.com/";
|
|
|
|
std::vector<std::string> base_urls_;
|
2023-12-01 17:32:19 +00:00
|
|
|
base_urls_.emplace_back(kBaseUrl1);
|
|
|
|
base_urls_.emplace_back(kBaseUrl2);
|
2015-09-14 19:53:32 +00:00
|
|
|
|
|
|
|
notifier_factory_->SetExpectedBaseUrls(base_urls_);
|
2014-01-28 23:06:58 +00:00
|
|
|
|
2023-12-01 17:32:19 +00:00
|
|
|
std::filesystem::path media_info_file1 =
|
2014-02-05 02:32:46 +00:00
|
|
|
GetTestDataFilePath(kFileNameVideoMediaInfo1);
|
2023-12-01 17:32:19 +00:00
|
|
|
std::filesystem::path media_info_file2 =
|
2014-02-05 02:32:46 +00:00
|
|
|
GetTestDataFilePath(kFileNameVideoMediaInfo2);
|
2014-01-28 23:06:58 +00:00
|
|
|
|
2015-09-14 19:53:32 +00:00
|
|
|
SetMpdNotifierFactoryForTest();
|
2023-12-01 17:32:19 +00:00
|
|
|
EXPECT_TRUE(mpd_writer_.AddFile(media_info_file1.string()));
|
|
|
|
EXPECT_TRUE(mpd_writer_.AddFile(media_info_file2.string()));
|
2015-09-14 19:53:32 +00:00
|
|
|
mpd_writer_.AddBaseUrl(kBaseUrl1);
|
|
|
|
mpd_writer_.AddBaseUrl(kBaseUrl2);
|
2014-02-28 22:34:26 +00:00
|
|
|
|
2023-12-01 17:32:19 +00:00
|
|
|
auto temp = new TempFile();
|
|
|
|
EXPECT_TRUE(mpd_writer_.WriteMpdToFile(temp->path().c_str()));
|
2015-02-02 17:26:09 +00:00
|
|
|
}
|
|
|
|
|
2016-05-20 21:19:33 +00:00
|
|
|
} // namespace shaka
|