Merge latest oemcrypto-v17 change
No-Typo-Check: Not related to this change. Bug: 161477208 Change-Id: I99e4780f6855b7045aa0cd5a49c13d2d0d51ed64
This commit is contained in:
committed by
Fred Gylys-Colwell
parent
c924960962
commit
642965c678
@@ -2,14 +2,15 @@
|
||||
// source code may only be used and distributed under the Widevine License
|
||||
// Agreement.
|
||||
|
||||
#include "file_store.h"
|
||||
|
||||
#include <gmock/gmock.h>
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include "cdm_random.h"
|
||||
#include "file_store.h"
|
||||
#include "test_vectors.h"
|
||||
|
||||
namespace wvcdm {
|
||||
namespace wvutil {
|
||||
|
||||
namespace {
|
||||
const std::string kTestDirName = "test_dir";
|
||||
@@ -31,26 +32,26 @@ class FileTest : public testing::Test {
|
||||
void TearDown() override { RemoveTestDir(); }
|
||||
|
||||
void RemoveTestDir() {
|
||||
EXPECT_TRUE(file_system_.Remove(test_vectors::kTestDir));
|
||||
EXPECT_TRUE(file_system_.Remove(wvcdm::test_vectors::kTestDir));
|
||||
}
|
||||
|
||||
FileSystem file_system_;
|
||||
};
|
||||
|
||||
TEST_F(FileTest, FileExists) {
|
||||
EXPECT_TRUE(file_system_.Exists(test_vectors::kExistentFile));
|
||||
EXPECT_TRUE(file_system_.Exists(test_vectors::kExistentDir));
|
||||
EXPECT_FALSE(file_system_.Exists(test_vectors::kNonExistentFile));
|
||||
EXPECT_FALSE(file_system_.Exists(test_vectors::kNonExistentDir));
|
||||
EXPECT_TRUE(file_system_.Exists(wvcdm::test_vectors::kExistentFile));
|
||||
EXPECT_TRUE(file_system_.Exists(wvcdm::test_vectors::kExistentDir));
|
||||
EXPECT_FALSE(file_system_.Exists(wvcdm::test_vectors::kNonExistentFile));
|
||||
EXPECT_FALSE(file_system_.Exists(wvcdm::test_vectors::kNonExistentDir));
|
||||
}
|
||||
|
||||
TEST_F(FileTest, RemoveDir) {
|
||||
EXPECT_TRUE(file_system_.Remove(test_vectors::kTestDir));
|
||||
EXPECT_FALSE(file_system_.Exists(test_vectors::kTestDir));
|
||||
EXPECT_TRUE(file_system_.Remove(wvcdm::test_vectors::kTestDir));
|
||||
EXPECT_FALSE(file_system_.Exists(wvcdm::test_vectors::kTestDir));
|
||||
}
|
||||
|
||||
TEST_F(FileTest, OpenFile) {
|
||||
std::string path = test_vectors::kTestDir + kTestFileName;
|
||||
std::string path = wvcdm::test_vectors::kTestDir + kTestFileName;
|
||||
EXPECT_TRUE(file_system_.Remove(path));
|
||||
|
||||
std::unique_ptr<File> file = file_system_.Open(path, FileSystem::kCreate);
|
||||
@@ -60,7 +61,7 @@ TEST_F(FileTest, OpenFile) {
|
||||
}
|
||||
|
||||
TEST_F(FileTest, RemoveDirAndFile) {
|
||||
std::string path = test_vectors::kTestDir + kTestFileName;
|
||||
std::string path = wvcdm::test_vectors::kTestDir + kTestFileName;
|
||||
|
||||
std::unique_ptr<File> file = file_system_.Open(path, FileSystem::kCreate);
|
||||
ASSERT_TRUE(file);
|
||||
@@ -74,15 +75,15 @@ TEST_F(FileTest, RemoveDirAndFile) {
|
||||
|
||||
EXPECT_TRUE(file_system_.Exists(path));
|
||||
RemoveTestDir();
|
||||
EXPECT_FALSE(file_system_.Exists(test_vectors::kTestDir));
|
||||
EXPECT_FALSE(file_system_.Exists(wvcdm::test_vectors::kTestDir));
|
||||
EXPECT_FALSE(file_system_.Exists(path));
|
||||
}
|
||||
|
||||
TEST_F(FileTest, RemoveWildcardFiles) {
|
||||
std::string path1 = test_vectors::kTestDir + kTestFileName;
|
||||
std::string path2 = test_vectors::kTestDir + kTestFileName2;
|
||||
std::string path1 = wvcdm::test_vectors::kTestDir + kTestFileName;
|
||||
std::string path2 = wvcdm::test_vectors::kTestDir + kTestFileName2;
|
||||
std::string wildcard_path =
|
||||
test_vectors::kTestDir + kWildcard + kTestFileNameExt;
|
||||
wvcdm::test_vectors::kTestDir + kWildcard + kTestFileNameExt;
|
||||
|
||||
std::unique_ptr<File> file = file_system_.Open(path1, FileSystem::kCreate);
|
||||
ASSERT_TRUE(file);
|
||||
@@ -97,7 +98,7 @@ TEST_F(FileTest, RemoveWildcardFiles) {
|
||||
}
|
||||
|
||||
TEST_F(FileTest, FileSize) {
|
||||
std::string path = test_vectors::kTestDir + kTestFileName;
|
||||
std::string path = wvcdm::test_vectors::kTestDir + kTestFileName;
|
||||
file_system_.Remove(path);
|
||||
|
||||
std::string write_data = CdmRandom::RandomData(600);
|
||||
@@ -111,7 +112,7 @@ TEST_F(FileTest, FileSize) {
|
||||
}
|
||||
|
||||
TEST_F(FileTest, WriteReadBinaryFile) {
|
||||
std::string path = test_vectors::kTestDir + kTestFileName;
|
||||
std::string path = wvcdm::test_vectors::kTestDir + kTestFileName;
|
||||
file_system_.Remove(path);
|
||||
|
||||
std::string write_data = CdmRandom::RandomData(600);
|
||||
@@ -134,10 +135,10 @@ TEST_F(FileTest, ListFiles) {
|
||||
std::vector<std::string> names;
|
||||
|
||||
std::string not_path("zzz");
|
||||
std::string path1 = test_vectors::kTestDir + kTestFileName;
|
||||
std::string path2 = test_vectors::kTestDir + kTestFileName2;
|
||||
std::string path3 = test_vectors::kTestDir + kTestFileName3;
|
||||
std::string path_dir = test_vectors::kTestDir;
|
||||
std::string path1 = wvcdm::test_vectors::kTestDir + kTestFileName;
|
||||
std::string path2 = wvcdm::test_vectors::kTestDir + kTestFileName2;
|
||||
std::string path3 = wvcdm::test_vectors::kTestDir + kTestFileName3;
|
||||
std::string path_dir = wvcdm::test_vectors::kTestDir;
|
||||
|
||||
std::unique_ptr<File> file = file_system_.Open(path1, FileSystem::kCreate);
|
||||
ASSERT_TRUE(file);
|
||||
@@ -181,7 +182,7 @@ TEST_F(FileTest, ListFiles) {
|
||||
TEST_F(FileTest, CreateGlobalCertificates) {
|
||||
// Clear directory
|
||||
std::vector<std::string> names;
|
||||
std::string path_dir = test_vectors::kTestDir;
|
||||
std::string path_dir = wvcdm::test_vectors::kTestDir;
|
||||
std::string wild_card_path = path_dir + kWildcard;
|
||||
file_system_.Remove(wild_card_path);
|
||||
if (file_system_.List(path_dir, &names)) {
|
||||
@@ -189,9 +190,10 @@ TEST_F(FileTest, CreateGlobalCertificates) {
|
||||
}
|
||||
|
||||
// Create certificates and verify that they exist
|
||||
std::string certificate_path = test_vectors::kTestDir + kCertificateFileName;
|
||||
std::string certificate_path =
|
||||
wvcdm::test_vectors::kTestDir + kCertificateFileName;
|
||||
std::string legacy_certificate_path =
|
||||
test_vectors::kTestDir + kLegacyCertificateFileName;
|
||||
wvcdm::test_vectors::kTestDir + kLegacyCertificateFileName;
|
||||
|
||||
std::unique_ptr<File> file =
|
||||
file_system_.Open(certificate_path, FileSystem::kCreate);
|
||||
@@ -214,16 +216,17 @@ TEST_F(FileTest, CreateGlobalCertificates) {
|
||||
TEST_F(FileTest, CreateCertificates) {
|
||||
// Clear directory
|
||||
std::vector<std::string> names;
|
||||
std::string path_dir = test_vectors::kTestDir;
|
||||
std::string path_dir = wvcdm::test_vectors::kTestDir;
|
||||
std::string wild_card_path = path_dir + kWildcard;
|
||||
file_system_.Remove(wild_card_path);
|
||||
if (file_system_.List(path_dir, &names)) {
|
||||
EXPECT_EQ(0u, names.size());
|
||||
}
|
||||
|
||||
std::string certificate_path = test_vectors::kTestDir + kCertificateFileName;
|
||||
std::string certificate_path =
|
||||
wvcdm::test_vectors::kTestDir + kCertificateFileName;
|
||||
std::string legacy_certificate_path =
|
||||
test_vectors::kTestDir + kLegacyCertificateFileName;
|
||||
wvcdm::test_vectors::kTestDir + kLegacyCertificateFileName;
|
||||
|
||||
// Create Global certificates
|
||||
std::unique_ptr<File> file =
|
||||
@@ -285,16 +288,17 @@ TEST_F(FileTest, CreateCertificates) {
|
||||
TEST_F(FileTest, RemoveCertificates) {
|
||||
// Clear directory
|
||||
std::vector<std::string> names;
|
||||
std::string path_dir = test_vectors::kTestDir;
|
||||
std::string path_dir = wvcdm::test_vectors::kTestDir;
|
||||
std::string wild_card_path = path_dir + kWildcard;
|
||||
file_system_.Remove(wild_card_path);
|
||||
if (file_system_.List(path_dir, &names)) {
|
||||
EXPECT_EQ(0u, names.size());
|
||||
}
|
||||
|
||||
std::string certificate_path = test_vectors::kTestDir + kCertificateFileName;
|
||||
std::string certificate_path =
|
||||
wvcdm::test_vectors::kTestDir + kCertificateFileName;
|
||||
std::string legacy_certificate_path =
|
||||
test_vectors::kTestDir + kLegacyCertificateFileName;
|
||||
wvcdm::test_vectors::kTestDir + kLegacyCertificateFileName;
|
||||
|
||||
// Create Global certificates
|
||||
std::unique_ptr<File> file =
|
||||
@@ -330,30 +334,34 @@ TEST_F(FileTest, RemoveCertificates) {
|
||||
// Remove all even number listed files
|
||||
for (size_t i = 0; i < names.size(); ++i) {
|
||||
if (i % 2 == 0) {
|
||||
EXPECT_TRUE(file_system_.Remove(test_vectors::kTestDir + names[i]));
|
||||
EXPECT_TRUE(
|
||||
file_system_.Remove(wvcdm::test_vectors::kTestDir + names[i]));
|
||||
}
|
||||
}
|
||||
|
||||
// Verify that they have been removed
|
||||
for (size_t i = 0; i < names.size(); ++i) {
|
||||
if (i % 2 == 1) {
|
||||
EXPECT_TRUE(file_system_.Exists(test_vectors::kTestDir + names[i]));
|
||||
EXPECT_TRUE(
|
||||
file_system_.Exists(wvcdm::test_vectors::kTestDir + names[i]));
|
||||
} else {
|
||||
EXPECT_FALSE(file_system_.Exists(test_vectors::kTestDir + names[i]));
|
||||
EXPECT_FALSE(
|
||||
file_system_.Exists(wvcdm::test_vectors::kTestDir + names[i]));
|
||||
}
|
||||
}
|
||||
|
||||
// Remove all odd number listed files
|
||||
for (size_t i = 0; i < names.size(); ++i) {
|
||||
if (i % 2 == 1) {
|
||||
EXPECT_TRUE(file_system_.Remove(test_vectors::kTestDir + names[i]));
|
||||
EXPECT_TRUE(
|
||||
file_system_.Remove(wvcdm::test_vectors::kTestDir + names[i]));
|
||||
}
|
||||
}
|
||||
|
||||
// Verify that all have been removed
|
||||
for (size_t i = 0; i < names.size(); ++i) {
|
||||
EXPECT_FALSE(file_system_.Exists(test_vectors::kTestDir + names[i]));
|
||||
EXPECT_FALSE(file_system_.Exists(wvcdm::test_vectors::kTestDir + names[i]));
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace wvcdm
|
||||
} // namespace wvutil
|
||||
|
||||
Reference in New Issue
Block a user