Update handling of move-only types in DeviceFiles unit test
(This is a merge of http://go/wvgerrit/139569.) The unit test for DeviceFiles previously had to work around googlemock's lack of support for move-only types. Now that we have upgraded to googletest 1.10, we can use move-only types directly via the ByMove() utility, removing the need for this workaround. Bug: 207693599 Test: x86-64 Change-Id: Ib4dcc5ec367ef413465a3e8a8f45f9187976ed5e
This commit is contained in:
@@ -3756,15 +3756,7 @@ class MockFileSystem : public FileSystem {
|
||||
MockFileSystem() {}
|
||||
~MockFileSystem() {}
|
||||
|
||||
// Until gmock is updated to a version post-April 2017, we need this
|
||||
// workaround to test functions that take or return smart pointers.
|
||||
// See
|
||||
// https://github.com/abseil/googletest/blob/master/googlemock/docs/CookBook.md#legacy-workarounds-for-move-only-types
|
||||
std::unique_ptr<File> Open(const std::string& buffer, int flags) {
|
||||
return std::unique_ptr<File>(DoOpen(buffer, flags));
|
||||
}
|
||||
|
||||
MOCK_METHOD2(DoOpen, File*(const std::string&, int flags));
|
||||
MOCK_METHOD2(Open, std::unique_ptr<File>(const std::string&, int flags));
|
||||
MOCK_METHOD0(IsFactoryReset, bool());
|
||||
|
||||
MOCK_METHOD1(Exists, bool(const std::string&));
|
||||
@@ -3780,6 +3772,7 @@ using ::testing::_;
|
||||
using ::testing::AllArgs;
|
||||
using ::testing::AllOf;
|
||||
using ::testing::AtLeast;
|
||||
using ::testing::ByMove;
|
||||
using ::testing::DoAll;
|
||||
using ::testing::Eq;
|
||||
using ::testing::Expectation;
|
||||
@@ -3931,8 +3924,8 @@ TEST_P(StoreCertificateTest, DefaultAndLegacy) {
|
||||
// Call to Open will return a unique_ptr, freeing this object.
|
||||
MockFile* file = new MockFile();
|
||||
EXPECT_CALL(file_system,
|
||||
DoOpen(StrEq(device_certificate_path), IsCreateFileFlagSet()))
|
||||
.WillOnce(Return(file));
|
||||
Open(StrEq(device_certificate_path), IsCreateFileFlagSet()))
|
||||
.WillOnce(Return(ByMove(std::unique_ptr<File>(file))));
|
||||
EXPECT_CALL(*file, Write(_, _))
|
||||
.With(AllArgs(StrAndLenContains(
|
||||
std::vector<std::string>{certificate, private_key.key()})))
|
||||
@@ -3979,8 +3972,8 @@ TEST_F(DeviceFilesTest, RetrieveAtscCertificate) {
|
||||
.WillRepeatedly(Return(true));
|
||||
EXPECT_CALL(file_system, FileSize(StrEq(device_certificate_path)))
|
||||
.WillOnce(Return(data.size()));
|
||||
EXPECT_CALL(file_system, DoOpen(StrEq(device_certificate_path), _))
|
||||
.WillOnce(Return(file));
|
||||
EXPECT_CALL(file_system, Open(StrEq(device_certificate_path), _))
|
||||
.WillOnce(Return(ByMove(std::unique_ptr<File>(file))));
|
||||
EXPECT_CALL(*file, Read(NotNull(), Eq(data.size())))
|
||||
.WillOnce(DoAll(SetArrayArgument<0>(data.begin(), data.end()),
|
||||
Return(data.size())));
|
||||
@@ -4051,9 +4044,9 @@ TEST_F(DeviceFilesTest, RetrieveLegacyCertificateWithoutExpirationTime) {
|
||||
.WillOnce(Return(data.size()));
|
||||
// Retrieving the legacy license will cause a read as well as a write
|
||||
// to fill in a random expiry date ~6 months later if one has not been set
|
||||
EXPECT_CALL(file_system, DoOpen(StrEq(device_legacy_certificate_path), _))
|
||||
.WillOnce(Return(read_file))
|
||||
.WillOnce(Return(write_file));
|
||||
EXPECT_CALL(file_system, Open(StrEq(device_legacy_certificate_path), _))
|
||||
.WillOnce(Return(ByMove(std::unique_ptr<File>(read_file))))
|
||||
.WillOnce(Return(ByMove(std::unique_ptr<File>(write_file))));
|
||||
EXPECT_CALL(*read_file, Read(NotNull(), Eq(data.size())))
|
||||
.WillOnce(DoAll(SetArrayArgument<0>(data.begin(), data.end()),
|
||||
Return(data.size())));
|
||||
@@ -4103,8 +4096,8 @@ TEST_F(DeviceFilesTest, RetrieveLegacyCertificateWithClientExpirationTime) {
|
||||
.WillRepeatedly(Return(false));
|
||||
EXPECT_CALL(file_system, FileSize(StrEq(device_legacy_certificate_path)))
|
||||
.WillOnce(Return(data.size()));
|
||||
EXPECT_CALL(file_system, DoOpen(StrEq(device_legacy_certificate_path), _))
|
||||
.WillOnce(Return(read_file));
|
||||
EXPECT_CALL(file_system, Open(StrEq(device_legacy_certificate_path), _))
|
||||
.WillOnce(Return(ByMove(std::unique_ptr<File>(read_file))));
|
||||
EXPECT_CALL(*read_file, Read(NotNull(), Eq(data.size())))
|
||||
.WillOnce(DoAll(SetArrayArgument<0>(data.begin(), data.end()),
|
||||
Return(data.size())));
|
||||
@@ -4157,8 +4150,8 @@ TEST_P(RetrieveLegacyCertificateTest, ErrorScenarios) {
|
||||
.WillRepeatedly(Return(false));
|
||||
EXPECT_CALL(file_system, FileSize(StrEq(device_legacy_certificate_path)))
|
||||
.WillOnce(Return(data.size()));
|
||||
EXPECT_CALL(file_system, DoOpen(StrEq(device_legacy_certificate_path), _))
|
||||
.WillOnce(Return(read_file));
|
||||
EXPECT_CALL(file_system, Open(StrEq(device_legacy_certificate_path), _))
|
||||
.WillOnce(Return(ByMove(std::unique_ptr<File>(read_file))));
|
||||
EXPECT_CALL(*read_file, Read(NotNull(), Eq(data.size())))
|
||||
.WillOnce(DoAll(SetArrayArgument<0>(data.begin(), data.end()),
|
||||
Return(data.size())));
|
||||
@@ -4203,8 +4196,8 @@ TEST_F(DeviceFilesTest, RetrieveDefaultCertificate) {
|
||||
.WillRepeatedly(Return(true));
|
||||
EXPECT_CALL(file_system, FileSize(StrEq(device_certificate_path)))
|
||||
.WillOnce(Return(data.size()));
|
||||
EXPECT_CALL(file_system, DoOpen(StrEq(device_certificate_path), _))
|
||||
.WillOnce(Return(read_file));
|
||||
EXPECT_CALL(file_system, Open(StrEq(device_certificate_path), _))
|
||||
.WillOnce(Return(ByMove(std::unique_ptr<File>(read_file))));
|
||||
EXPECT_CALL(*read_file, Read(NotNull(), Eq(data.size())))
|
||||
.WillOnce(DoAll(SetArrayArgument<0>(data.begin(), data.end()),
|
||||
Return(data.size())));
|
||||
@@ -4244,8 +4237,8 @@ TEST_F(DeviceFilesTest, RetrieveDefaultCertificateNeverExpires) {
|
||||
.WillRepeatedly(Return(true));
|
||||
EXPECT_CALL(file_system, FileSize(StrEq(device_certificate_path)))
|
||||
.WillOnce(Return(data.size()));
|
||||
EXPECT_CALL(file_system, DoOpen(StrEq(device_certificate_path), _))
|
||||
.WillOnce(Return(read_file));
|
||||
EXPECT_CALL(file_system, Open(StrEq(device_certificate_path), _))
|
||||
.WillOnce(Return(ByMove(std::unique_ptr<File>(read_file))));
|
||||
EXPECT_CALL(*read_file, Read(NotNull(), Eq(data.size())))
|
||||
.WillOnce(DoAll(SetArrayArgument<0>(data.begin(), data.end()),
|
||||
Return(data.size())));
|
||||
@@ -4291,8 +4284,8 @@ TEST_P(RetrieveDefaultCertificateTest, ErrorScenarios) {
|
||||
.WillRepeatedly(Return(true));
|
||||
EXPECT_CALL(file_system, FileSize(StrEq(device_certificate_path)))
|
||||
.WillOnce(Return(data.size()));
|
||||
EXPECT_CALL(file_system, DoOpen(StrEq(device_certificate_path), _))
|
||||
.WillOnce(Return(read_file));
|
||||
EXPECT_CALL(file_system, Open(StrEq(device_certificate_path), _))
|
||||
.WillOnce(Return(ByMove(std::unique_ptr<File>(read_file))));
|
||||
EXPECT_CALL(*read_file, Read(NotNull(), Eq(data.size())))
|
||||
.WillOnce(DoAll(SetArrayArgument<0>(data.begin(), data.end()),
|
||||
Return(data.size())));
|
||||
@@ -4348,10 +4341,10 @@ TEST_F(DeviceFilesTest, RetrieveCertificateWithoutKeyType) {
|
||||
.WillRepeatedly(Return(false));
|
||||
EXPECT_CALL(file_system, FileSize(StrEq(device_legacy_certificate_path)))
|
||||
.WillOnce(Return(data.size()));
|
||||
EXPECT_CALL(file_system, DoOpen(StrEq(device_legacy_certificate_path), _))
|
||||
.WillOnce(Return(read_file));
|
||||
EXPECT_CALL(file_system, Open(StrEq(device_legacy_certificate_path), _))
|
||||
.WillOnce(Return(ByMove(std::unique_ptr<File>(read_file))));
|
||||
/* TODO(b/192430982): Renable expiration of legacy DRM certificates
|
||||
.WillOnce(Return(write_file));
|
||||
.WillOnce(Return(ByMove(std::unique_ptr<File>(write_file))));
|
||||
*/
|
||||
EXPECT_CALL(*read_file, Read(NotNull(), Eq(data.size())))
|
||||
.WillOnce(DoAll(SetArrayArgument<0>(data.begin(), data.end()),
|
||||
@@ -4391,7 +4384,7 @@ TEST_F(DeviceFilesTest, HasCertificateAtsc) {
|
||||
EXPECT_CALL(file_system, Exists(StrEq(device_certificate_path)))
|
||||
.WillOnce(Return(false))
|
||||
.WillOnce(Return(true));
|
||||
EXPECT_CALL(file_system, DoOpen(_, _)).Times(0);
|
||||
EXPECT_CALL(file_system, Open(_, _)).Times(0);
|
||||
|
||||
DeviceFiles device_files(&file_system);
|
||||
ASSERT_TRUE(device_files.Init(kSecurityLevelL1));
|
||||
@@ -4412,7 +4405,7 @@ TEST_F(DeviceFilesTest, HasCertificateDefault) {
|
||||
|
||||
EXPECT_CALL(file_system, Exists(StrEq(device_certificate_path)))
|
||||
.WillOnce(Return(true));
|
||||
EXPECT_CALL(file_system, DoOpen(_, _)).Times(0);
|
||||
EXPECT_CALL(file_system, Open(_, _)).Times(0);
|
||||
|
||||
DeviceFiles device_files(&file_system);
|
||||
ASSERT_TRUE(device_files.Init(kSecurityLevelL1));
|
||||
@@ -4436,7 +4429,7 @@ TEST_F(DeviceFilesTest, HasCertificateLegacy) {
|
||||
.WillOnce(Return(false));
|
||||
EXPECT_CALL(file_system, Exists(StrEq(device_legacy_certificate_path)))
|
||||
.WillOnce(Return(true));
|
||||
EXPECT_CALL(file_system, DoOpen(_, _)).Times(0);
|
||||
EXPECT_CALL(file_system, Open(_, _)).Times(0);
|
||||
|
||||
DeviceFiles device_files(&file_system);
|
||||
ASSERT_TRUE(device_files.Init(kSecurityLevelL1));
|
||||
@@ -4460,7 +4453,7 @@ TEST_F(DeviceFilesTest, HasCertificateNone) {
|
||||
.WillOnce(Return(false));
|
||||
EXPECT_CALL(file_system, Exists(StrEq(device_legacy_certificate_path)))
|
||||
.WillOnce(Return(false));
|
||||
EXPECT_CALL(file_system, DoOpen(_, _)).Times(0);
|
||||
EXPECT_CALL(file_system, Open(_, _)).Times(0);
|
||||
|
||||
DeviceFiles device_files(&file_system);
|
||||
ASSERT_TRUE(device_files.Init(kSecurityLevelL1));
|
||||
@@ -4487,8 +4480,8 @@ TEST_P(DeviceFilesSecurityLevelTest, SecurityLevel) {
|
||||
// Call to Open will return a unique_ptr, freeing this object.
|
||||
MockFile* file = new MockFile();
|
||||
EXPECT_CALL(file_system,
|
||||
DoOpen(StrEq(device_certificate_path), IsCreateFileFlagSet()))
|
||||
.WillOnce(Return(file));
|
||||
Open(StrEq(device_certificate_path), IsCreateFileFlagSet()))
|
||||
.WillOnce(Return(ByMove(std::unique_ptr<File>(file))));
|
||||
EXPECT_CALL(*file, Write(_, _))
|
||||
.With(AllArgs(StrAndLenContains(
|
||||
std::vector<std::string>{certificate, private_key.key()})))
|
||||
@@ -4529,8 +4522,8 @@ TEST_P(DeviceFilesStoreTest, StoreLicense) {
|
||||
|
||||
// Call to Open will return a unique_ptr, freeing this object.
|
||||
MockFile* file = new MockFile();
|
||||
EXPECT_CALL(file_system, DoOpen(StrEq(license_path), IsCreateFileFlagSet()))
|
||||
.WillOnce(Return(file));
|
||||
EXPECT_CALL(file_system, Open(StrEq(license_path), IsCreateFileFlagSet()))
|
||||
.WillOnce(Return(ByMove(std::unique_ptr<File>(file))));
|
||||
EXPECT_CALL(*file, Write(_, _))
|
||||
.With(AllArgs(StrAndLenContains(expected_substrings)))
|
||||
.WillOnce(ReturnArg<1>());
|
||||
@@ -4593,8 +4586,8 @@ TEST_F(DeviceFilesTest, StoreLicenses) {
|
||||
|
||||
// Call to Open will return a unique_ptr, freeing this object.
|
||||
MockFile* file = new MockFile();
|
||||
EXPECT_CALL(file_system, DoOpen(StrEq(license_path), IsCreateFileFlagSet()))
|
||||
.WillOnce(Return(file));
|
||||
EXPECT_CALL(file_system, Open(StrEq(license_path), IsCreateFileFlagSet()))
|
||||
.WillOnce(Return(ByMove(std::unique_ptr<File>(file))));
|
||||
|
||||
EXPECT_CALL(*file, Write(_, _))
|
||||
.With(AllArgs(StrAndLenContains(expected_substrings)))
|
||||
@@ -4649,8 +4642,8 @@ TEST_F(DeviceFilesTest, RetrieveLicenses) {
|
||||
.WillOnce(Return(true));
|
||||
EXPECT_CALL(file_system, FileSize(StrEq(license_path)))
|
||||
.WillOnce(Return(size));
|
||||
EXPECT_CALL(file_system, DoOpen(StrEq(license_path), _))
|
||||
.WillOnce(Return(file));
|
||||
EXPECT_CALL(file_system, Open(StrEq(license_path), _))
|
||||
.WillOnce(Return(ByMove(std::unique_ptr<File>(file))));
|
||||
EXPECT_CALL(*file, Read(NotNull(), Eq(size)))
|
||||
.WillOnce(
|
||||
DoAll(SetArrayArgument<0>(kLicenseTestData[i].file_data.begin(),
|
||||
@@ -4720,8 +4713,8 @@ TEST_F(DeviceFilesTest, AppParametersBackwardCompatibility) {
|
||||
EXPECT_CALL(file_system, Exists(StrEq(license_path))).WillOnce(Return(true));
|
||||
EXPECT_CALL(file_system, FileSize(StrEq(license_path)))
|
||||
.WillOnce(Return(size));
|
||||
EXPECT_CALL(file_system, DoOpen(StrEq(license_path), _))
|
||||
.WillOnce(Return(file));
|
||||
EXPECT_CALL(file_system, Open(StrEq(license_path), _))
|
||||
.WillOnce(Return(ByMove(std::unique_ptr<File>(file))));
|
||||
EXPECT_CALL(*file, Read(NotNull(), Eq(size)))
|
||||
.WillOnce(DoAll(SetArrayArgument<0>(test_data->file_data.begin(),
|
||||
test_data->file_data.end()),
|
||||
@@ -4768,8 +4761,8 @@ TEST_F(DeviceFilesTest, UpdateLicenseState) {
|
||||
for (size_t i = 0; i < ArraySize(kLicenseUpdateTestData); i++) {
|
||||
// Call to Open will return a unique_ptr, freeing this object.
|
||||
MockFile* file = new MockFile();
|
||||
EXPECT_CALL(file_system, DoOpen(StrEq(license_path), IsCreateFileFlagSet()))
|
||||
.WillOnce(Return(file));
|
||||
EXPECT_CALL(file_system, Open(StrEq(license_path), IsCreateFileFlagSet()))
|
||||
.WillOnce(Return(ByMove(std::unique_ptr<File>(file))));
|
||||
EXPECT_CALL(*file, Write(_, _))
|
||||
.With(AllArgs(StrAndLenEq(kLicenseUpdateTestData[i].file_data)))
|
||||
.WillOnce(ReturnArg<1>());
|
||||
@@ -4814,8 +4807,8 @@ TEST_F(DeviceFilesTest, DeleteLicense) {
|
||||
.WillOnce(Return(false));
|
||||
EXPECT_CALL(file_system, FileSize(StrEq(license_path)))
|
||||
.WillOnce(Return(size));
|
||||
EXPECT_CALL(file_system, DoOpen(StrEq(license_path), _))
|
||||
.WillOnce(Return(file));
|
||||
EXPECT_CALL(file_system, Open(StrEq(license_path), _))
|
||||
.WillOnce(Return(ByMove(std::unique_ptr<File>(file))));
|
||||
EXPECT_CALL(*file, Read(NotNull(), Eq(size)))
|
||||
.WillOnce(DoAll(SetArrayArgument<0>(kLicenseTestData[0].file_data.begin(),
|
||||
kLicenseTestData[0].file_data.end()),
|
||||
@@ -4870,7 +4863,7 @@ TEST_F(DeviceFilesTest, DeleteLicense) {
|
||||
TEST_F(DeviceFilesTest, ReserveLicenseIdsDoesNotUseFileSystem) {
|
||||
// Validate that ReserveLicenseIds does not touch the file system.
|
||||
MockFileSystem file_system;
|
||||
EXPECT_CALL(file_system, DoOpen(_, _)).Times(0);
|
||||
EXPECT_CALL(file_system, Open(_, _)).Times(0);
|
||||
|
||||
DeviceFiles device_files(&file_system);
|
||||
EXPECT_TRUE(device_files.Init(kSecurityLevelL1));
|
||||
@@ -4961,7 +4954,8 @@ TEST_F(DeviceFilesTest, OkpInfo_StoreAndRetrieve) {
|
||||
const std::string kOkpInfoPath =
|
||||
device_base_path_ + DeviceFiles::GetOkpInfoFileName();
|
||||
MockFile* file = new MockFile();
|
||||
EXPECT_CALL(file_system, DoOpen(kOkpInfoPath, _)).WillOnce(Return(file));
|
||||
EXPECT_CALL(file_system, Open(kOkpInfoPath, _))
|
||||
.WillOnce(Return(ByMove(std::unique_ptr<File>(file))));
|
||||
std::string serialized;
|
||||
EXPECT_CALL(*file, Write(NotNull(), _))
|
||||
.WillOnce(DoAll(Invoke([&](const char* buf, size_t len) {
|
||||
@@ -4977,7 +4971,8 @@ TEST_F(DeviceFilesTest, OkpInfo_StoreAndRetrieve) {
|
||||
EXPECT_CALL(file_system, Exists(kOkpInfoPath)).WillOnce(Return(true));
|
||||
EXPECT_CALL(file_system, FileSize(kOkpInfoPath))
|
||||
.WillOnce(Return(serialized.size()));
|
||||
EXPECT_CALL(file_system, DoOpen(kOkpInfoPath, _)).WillOnce(Return(file));
|
||||
EXPECT_CALL(file_system, Open(kOkpInfoPath, _))
|
||||
.WillOnce(Return(ByMove(std::unique_ptr<File>(file))));
|
||||
EXPECT_CALL(*file, Read(NotNull(), _))
|
||||
.WillOnce(DoAll(SetArrayArgument<0>(serialized.begin(), serialized.end()),
|
||||
Return(serialized.size())));
|
||||
@@ -5013,8 +5008,8 @@ TEST_P(DeviceFilesDeleteMultipleUsageInfoTest, DeleteAllButOne) {
|
||||
|
||||
// File read expectations.
|
||||
MockFile* file_in = new MockFile();
|
||||
EXPECT_CALL(file_system, DoOpen(file_path, FileSystem::kReadOnly))
|
||||
.WillOnce(Return(file_in));
|
||||
EXPECT_CALL(file_system, Open(file_path, FileSystem::kReadOnly))
|
||||
.WillOnce(Return(ByMove(std::unique_ptr<File>(file_in))));
|
||||
Expectation read_original =
|
||||
EXPECT_CALL(*file_in, Read(NotNull(), _))
|
||||
.WillOnce(
|
||||
@@ -5026,8 +5021,8 @@ TEST_P(DeviceFilesDeleteMultipleUsageInfoTest, DeleteAllButOne) {
|
||||
// File write expectations.
|
||||
MockFile* file_out = new MockFile();
|
||||
EXPECT_CALL(file_system,
|
||||
DoOpen(file_path, FileSystem::kCreate | FileSystem::kTruncate))
|
||||
.WillOnce(Return(file_out));
|
||||
Open(file_path, FileSystem::kCreate | FileSystem::kTruncate))
|
||||
.WillOnce(Return(ByMove(std::unique_ptr<File>(file_out))));
|
||||
EXPECT_CALL(*file_out, Write(StrEq(result_hashed_usage_info_file), _))
|
||||
.After(read_original)
|
||||
.WillOnce(Return(result_hashed_usage_info_file.size()));
|
||||
@@ -5067,8 +5062,8 @@ TEST_F(DeviceFilesDeleteMultipleUsageInfoTest, DeleteAllKeySetIds) {
|
||||
EXPECT_CALL(file_system, Exists(_)).WillRepeatedly(Return(true));
|
||||
EXPECT_CALL(file_system, FileSize(file_path))
|
||||
.WillOnce(Return(kHashedUsageInfoFileWithThreeKeySetIds.size()));
|
||||
EXPECT_CALL(file_system, DoOpen(file_path, FileSystem::kReadOnly))
|
||||
.WillOnce(Return(file_in));
|
||||
EXPECT_CALL(file_system, Open(file_path, FileSystem::kReadOnly))
|
||||
.WillOnce(Return(ByMove(std::unique_ptr<File>(file_in))));
|
||||
EXPECT_CALL(*file_in, Read(NotNull(), _))
|
||||
.WillOnce(DoAll(
|
||||
SetArrayArgument<0>(kHashedUsageInfoFileWithThreeKeySetIds.cbegin(),
|
||||
@@ -5104,8 +5099,8 @@ TEST_F(DeviceFilesDeleteMultipleUsageInfoTest, DeleteNone) {
|
||||
MockFile* file_in = new MockFile();
|
||||
EXPECT_CALL(file_system, FileSize(file_path))
|
||||
.WillOnce(Return(kHashedUsageInfoFileWithThreeKeySetIds.size()));
|
||||
EXPECT_CALL(file_system, DoOpen(file_path, FileSystem::kReadOnly))
|
||||
.WillOnce(Return(file_in));
|
||||
EXPECT_CALL(file_system, Open(file_path, FileSystem::kReadOnly))
|
||||
.WillOnce(Return(ByMove(std::unique_ptr<File>(file_in))));
|
||||
EXPECT_CALL(*file_in, Read(NotNull(), _))
|
||||
.WillOnce(DoAll(
|
||||
SetArrayArgument<0>(kHashedUsageInfoFileWithThreeKeySetIds.cbegin(),
|
||||
@@ -5140,8 +5135,8 @@ TEST_F(DeviceFilesDeleteMultipleUsageInfoTest, DeleteOne) {
|
||||
|
||||
// File read expectations.
|
||||
MockFile* file_in = new MockFile();
|
||||
EXPECT_CALL(file_system, DoOpen(file_path, FileSystem::kReadOnly))
|
||||
.WillOnce(Return(file_in));
|
||||
EXPECT_CALL(file_system, Open(file_path, FileSystem::kReadOnly))
|
||||
.WillOnce(Return(ByMove(std::unique_ptr<File>(file_in))));
|
||||
Expectation read_original =
|
||||
EXPECT_CALL(*file_in, Read(NotNull(), _))
|
||||
.WillOnce(DoAll(
|
||||
@@ -5152,8 +5147,8 @@ TEST_F(DeviceFilesDeleteMultipleUsageInfoTest, DeleteOne) {
|
||||
// File write expectations.
|
||||
MockFile* file_out = new MockFile();
|
||||
EXPECT_CALL(file_system,
|
||||
DoOpen(file_path, FileSystem::kCreate | FileSystem::kTruncate))
|
||||
.WillOnce(Return(file_out));
|
||||
Open(file_path, FileSystem::kCreate | FileSystem::kTruncate))
|
||||
.WillOnce(Return(ByMove(std::unique_ptr<File>(file_out))));
|
||||
EXPECT_CALL(*file_out, Write(StrEq(kHashedUsageInfoFileWithKeySet1), _))
|
||||
.After(read_original)
|
||||
.WillOnce(Return(kHashedUsageInfoFileWithKeySet1.size()));
|
||||
@@ -5191,8 +5186,8 @@ TEST_F(DeviceFilesDeleteMultipleUsageInfoTest, BadFile) {
|
||||
EXPECT_CALL(file_system, Exists(_)).WillRepeatedly(Return(true));
|
||||
EXPECT_CALL(file_system, FileSize(file_path))
|
||||
.WillOnce(Return(kHashlessUsageInfoFile.size()));
|
||||
EXPECT_CALL(file_system, DoOpen(file_path, FileSystem::kReadOnly))
|
||||
.WillOnce(Return(file_in));
|
||||
EXPECT_CALL(file_system, Open(file_path, FileSystem::kReadOnly))
|
||||
.WillOnce(Return(ByMove(std::unique_ptr<File>(file_in))));
|
||||
EXPECT_CALL(*file_in, Read(NotNull(), _))
|
||||
.WillOnce(DoAll(SetArrayArgument<0>(kHashlessUsageInfoFile.cbegin(),
|
||||
kHashlessUsageInfoFile.cend()),
|
||||
@@ -5241,7 +5236,8 @@ TEST_F(DeviceFilesUsageInfoTest, ListUsageIds) {
|
||||
EXPECT_CALL(file_system, FileSize(StrEq(path)))
|
||||
.Times(2)
|
||||
.WillRepeatedly(Return(kUsageInfoTestData[index].file_data.size()));
|
||||
EXPECT_CALL(file_system, DoOpen(StrEq(path), _)).WillOnce(Return(file));
|
||||
EXPECT_CALL(file_system, Open(StrEq(path), _))
|
||||
.WillOnce(Return(ByMove(std::unique_ptr<File>(file))));
|
||||
EXPECT_CALL(*file,
|
||||
Read(NotNull(), Eq(kUsageInfoTestData[index].file_data.size())))
|
||||
.WillOnce(DoAll(SetArrayArgument<0>(file_data.begin(), file_data.end()),
|
||||
@@ -5335,7 +5331,8 @@ TEST_P(DeviceFilesUsageInfoTest, Store) {
|
||||
}
|
||||
}
|
||||
|
||||
EXPECT_CALL(file_system, DoOpen(StrEq(path), _)).WillOnce(Return(file));
|
||||
EXPECT_CALL(file_system, Open(StrEq(path), _))
|
||||
.WillOnce(Return(ByMove(std::unique_ptr<File>(file))));
|
||||
EXPECT_CALL(*file, Write(_, _))
|
||||
.With(AllArgs(StrAndLenContains(usage_data_fields)))
|
||||
.WillOnce(ReturnArg<1>());
|
||||
@@ -5367,7 +5364,8 @@ TEST_P(DeviceFilesUsageInfoTest, Retrieve) {
|
||||
EXPECT_CALL(file_system, FileSize(StrEq(path)))
|
||||
.Times(2)
|
||||
.WillRepeatedly(Return(kUsageInfoTestData[index].file_data.size()));
|
||||
EXPECT_CALL(file_system, DoOpen(StrEq(path), _)).WillOnce(Return(file));
|
||||
EXPECT_CALL(file_system, Open(StrEq(path), _))
|
||||
.WillOnce(Return(ByMove(std::unique_ptr<File>(file))));
|
||||
EXPECT_CALL(*file,
|
||||
Read(NotNull(), Eq(kUsageInfoTestData[index].file_data.size())))
|
||||
.WillOnce(DoAll(SetArrayArgument<0>(file_data.begin(), file_data.end()),
|
||||
@@ -5434,7 +5432,8 @@ TEST_P(DeviceFilesUsageInfoTest, ListKeySetIds) {
|
||||
EXPECT_CALL(file_system, FileSize(StrEq(path)))
|
||||
.Times(2)
|
||||
.WillRepeatedly(Return(kUsageInfoTestData[index].file_data.size()));
|
||||
EXPECT_CALL(file_system, DoOpen(StrEq(path), _)).WillOnce(Return(file));
|
||||
EXPECT_CALL(file_system, Open(StrEq(path), _))
|
||||
.WillOnce(Return(ByMove(std::unique_ptr<File>(file))));
|
||||
EXPECT_CALL(*file,
|
||||
Read(NotNull(), Eq(kUsageInfoTestData[index].file_data.size())))
|
||||
.WillOnce(DoAll(SetArrayArgument<0>(file_data.begin(), file_data.end()),
|
||||
@@ -5484,7 +5483,8 @@ TEST_P(DeviceFilesUsageInfoTest, ListProviderSessionTokenIds) {
|
||||
EXPECT_CALL(file_system, FileSize(StrEq(path)))
|
||||
.Times(2)
|
||||
.WillRepeatedly(Return(kUsageInfoTestData[index].file_data.size()));
|
||||
EXPECT_CALL(file_system, DoOpen(StrEq(path), _)).WillOnce(Return(file));
|
||||
EXPECT_CALL(file_system, Open(StrEq(path), _))
|
||||
.WillOnce(Return(ByMove(std::unique_ptr<File>(file))));
|
||||
EXPECT_CALL(*file,
|
||||
Read(NotNull(), Eq(kUsageInfoTestData[index].file_data.size())))
|
||||
.WillOnce(DoAll(SetArrayArgument<0>(file_data.begin(), file_data.end()),
|
||||
@@ -5541,7 +5541,8 @@ TEST_P(DeviceFilesUsageInfoTest, RetrieveByProviderSessionToken) {
|
||||
EXPECT_CALL(file_system, Exists(StrEq(path))).WillOnce(Return(true));
|
||||
EXPECT_CALL(file_system, FileSize(StrEq(path)))
|
||||
.WillOnce(Return(file_data.size()));
|
||||
EXPECT_CALL(file_system, DoOpen(StrEq(path), _)).WillOnce(Return(file));
|
||||
EXPECT_CALL(file_system, Open(StrEq(path), _))
|
||||
.WillOnce(Return(ByMove(std::unique_ptr<File>(file))));
|
||||
EXPECT_CALL(*file, Read(NotNull(), Eq(file_data.size())))
|
||||
.WillOnce(DoAll(SetArrayArgument<0>(file_data.begin(), file_data.end()),
|
||||
Return(file_data.size())));
|
||||
@@ -5632,13 +5633,14 @@ TEST_P(DeviceFilesUsageInfoTest, UpdateUsageInfo) {
|
||||
|
||||
bool write_called = false;
|
||||
if (index < 0) {
|
||||
EXPECT_CALL(file_system, DoOpen(StrEq(path), _)).WillOnce(Return(file));
|
||||
EXPECT_CALL(file_system, Open(StrEq(path), _))
|
||||
.WillOnce(Return(ByMove(std::unique_ptr<File>(file))));
|
||||
} else {
|
||||
MockFile* next_file = new MockFile();
|
||||
EXPECT_CALL(file_system, DoOpen(StrEq(path), _))
|
||||
EXPECT_CALL(file_system, Open(StrEq(path), _))
|
||||
.Times(2)
|
||||
.WillOnce(Return(file))
|
||||
.WillOnce(Return(next_file));
|
||||
.WillOnce(Return(ByMove(std::unique_ptr<File>(file))))
|
||||
.WillOnce(Return(ByMove(std::unique_ptr<File>(next_file))));
|
||||
ON_CALL(*file, Write(_, _))
|
||||
.With(AllArgs(StrAndLenContains(usage_data_fields)))
|
||||
.WillByDefault(DoAll(InvokeWithoutArgs([&write_called]() -> void {
|
||||
@@ -5678,7 +5680,8 @@ TEST_P(DeviceFilesHlsAttributesTest, Read) {
|
||||
EXPECT_CALL(file_system, Exists(StrEq(path))).WillRepeatedly(Return(true));
|
||||
EXPECT_CALL(file_system, FileSize(StrEq(path)))
|
||||
.WillRepeatedly(Return(param->file_data.size()));
|
||||
EXPECT_CALL(file_system, DoOpen(StrEq(path), _)).WillOnce(Return(file));
|
||||
EXPECT_CALL(file_system, Open(StrEq(path), _))
|
||||
.WillOnce(Return(ByMove(std::unique_ptr<File>(file))));
|
||||
EXPECT_CALL(*file, Read(NotNull(), Eq(param->file_data.size())))
|
||||
.WillOnce(DoAll(
|
||||
SetArrayArgument<0>(param->file_data.begin(), param->file_data.end()),
|
||||
@@ -5707,7 +5710,8 @@ TEST_P(DeviceFilesHlsAttributesTest, Store) {
|
||||
DeviceFiles::GetHlsAttributesFileNameExtension();
|
||||
|
||||
EXPECT_CALL(file_system, Exists(StrEq(path))).WillRepeatedly(Return(true));
|
||||
EXPECT_CALL(file_system, DoOpen(StrEq(path), _)).WillOnce(Return(file));
|
||||
EXPECT_CALL(file_system, Open(StrEq(path), _))
|
||||
.WillOnce(Return(ByMove(std::unique_ptr<File>(file))));
|
||||
EXPECT_CALL(*file, Write(_, _))
|
||||
.With(AllArgs(
|
||||
StrAndLenContains(std::vector<std::string>{param->media_segment_iv})))
|
||||
@@ -5758,7 +5762,8 @@ TEST_P(DeviceFilesUsageTableTest, Store) {
|
||||
std::string path = device_base_path_ + DeviceFiles::GetUsageTableFileName();
|
||||
|
||||
EXPECT_CALL(file_system, Exists(StrEq(path))).WillRepeatedly(Return(true));
|
||||
EXPECT_CALL(file_system, DoOpen(StrEq(path), _)).WillOnce(Return(file));
|
||||
EXPECT_CALL(file_system, Open(StrEq(path), _))
|
||||
.WillOnce(Return(ByMove(std::unique_ptr<File>(file))));
|
||||
EXPECT_CALL(*file, Write(_, _))
|
||||
.With(AllArgs(StrAndLenContains(entry_data)))
|
||||
.WillOnce(ReturnArg<1>());
|
||||
@@ -5782,7 +5787,8 @@ TEST_P(DeviceFilesUsageTableTest, Read) {
|
||||
EXPECT_CALL(file_system, Exists(StrEq(path))).WillRepeatedly(Return(true));
|
||||
EXPECT_CALL(file_system, FileSize(StrEq(path)))
|
||||
.WillRepeatedly(Return(file_data.size()));
|
||||
EXPECT_CALL(file_system, DoOpen(StrEq(path), _)).WillOnce(Return(file));
|
||||
EXPECT_CALL(file_system, Open(StrEq(path), _))
|
||||
.WillOnce(Return(ByMove(std::unique_ptr<File>(file))));
|
||||
EXPECT_CALL(*file, Read(NotNull(), Eq(file_data.size())))
|
||||
.WillOnce(DoAll(SetArrayArgument<0>(file_data.begin(), file_data.end()),
|
||||
Return(file_data.size())));
|
||||
@@ -5834,7 +5840,8 @@ TEST_F(DeviceFilesUsageTableTest, ReadWithoutLruData) {
|
||||
EXPECT_CALL(file_system, Exists(StrEq(path))).WillRepeatedly(Return(true));
|
||||
EXPECT_CALL(file_system, FileSize(StrEq(path)))
|
||||
.WillRepeatedly(Return(kUsageTableWithoutLruData.size()));
|
||||
EXPECT_CALL(file_system, DoOpen(StrEq(path), _)).WillOnce(Return(file));
|
||||
EXPECT_CALL(file_system, Open(StrEq(path), _))
|
||||
.WillOnce(Return(ByMove(std::unique_ptr<File>(file))));
|
||||
|
||||
DeviceFiles device_files(&file_system);
|
||||
EXPECT_TRUE(device_files.Init(kSecurityLevelL1));
|
||||
|
||||
Reference in New Issue
Block a user