Revert "Merge latest oemcrypto-v17 change"

This reverts commit 642965c678.

Reason for revert: Droidfood Blocking Bug: 217145027

Change-Id: I669b72fcd91c62e28883b5f55eb36af274d85806
(cherry picked from commit 8dbea15e5da05b371572297041454569dc166c90)
Merged-In:I669b72fcd91c62e28883b5f55eb36af274d85806
This commit is contained in:
Daniel Chapin
2022-01-31 19:21:18 +00:00
committed by Android Build Coastguard Worker
parent 860a48ff8c
commit 5558e492c9
176 changed files with 296842 additions and 301106 deletions

View File

@@ -10,7 +10,7 @@
#include "string_conversions.h"
namespace wvutil {
namespace wvcdm {
// Advance an IV according to ISO-CENC's CTR modes. The lower half of the IV is
// split off and treated as an unsigned 64-bit integer, then incremented by the
@@ -41,6 +41,6 @@ inline void AdvanceIvCtr(uint8_t (*subsample_iv)[16], size_t bytes) {
memcpy(&(*subsample_iv)[kCounterIndex], &counter, kCounterSize);
}
} // namespace wvutil
} // namespace wvcdm
#endif // WVCDM_UTIL_ADVANCE_IV_CTR_H_

View File

@@ -7,7 +7,7 @@
#include <stdint.h>
namespace wvutil {
namespace wvcdm {
// Returns the size of a fixed-length array.
template <typename T, size_t N>
@@ -15,6 +15,6 @@ constexpr size_t ArraySize(const T (&)[N]) {
return N;
}
} // namespace wvutil
} // namespace wvcdm
#endif // WVCDM_UTIL_ARRAYSIZE_H_

View File

@@ -8,7 +8,7 @@
#include <random>
#include <string>
namespace wvutil {
namespace wvcdm {
// CdmRandomGenerator is a thread safe, pseudo-random number generator.
// It's purpose is to simplified interface for C++11's <random> library.
@@ -112,6 +112,6 @@ class CdmRandom {
static CdmRandomGenerator* GetInstance();
};
} // namespace wvutil
} // namespace wvcdm
#endif // WVCDM_CORE_CDM_RANDOM_H_

View File

@@ -9,7 +9,7 @@
#include <stdint.h>
namespace wvutil {
namespace wvcdm {
// Provides time related information. The implementation is platform dependent.
class Clock {
@@ -21,6 +21,6 @@ class Clock {
virtual int64_t GetCurrentTime();
};
} // namespace wvutil
} // namespace wvcdm
#endif // WVCDM_UTIL_CLOCK_H_

View File

@@ -5,12 +5,12 @@
#ifndef WVCDM_UTIL_DISALLOW_COPY_AND_ASSIGN_H_
#define WVCDM_UTIL_DISALLOW_COPY_AND_ASSIGN_H_
namespace wvutil {
namespace wvcdm {
#define CORE_DISALLOW_COPY_AND_ASSIGN(TypeName) \
TypeName(const TypeName&); \
void operator=(const TypeName&)
} // namespace wvutil
} // namespace wvcdm
#endif // WVCDM_UTIL_DISALLOW_COPY_AND_ASSIGN_H_

View File

@@ -16,7 +16,7 @@
#include "platform.h"
#include "util_common.h"
namespace wvutil {
namespace wvcdm {
static const std::string kAtscCertificateFileName = "atsccert.bin";
static const std::string kCertificateFileName = "cert1.bin";
@@ -24,8 +24,6 @@ static const std::string kCertificateFileNameExt = ".bin";
static const std::string kCertificateFileNamePrefix = "cert1_";
static const std::string kLegacyCertificateFileName = "cert.bin";
static const std::string kLegacyCertificateFileNamePrefix = "cert";
static const std::string kOemCertificateFileName = "oemcert.bin";
static const std::string kOemCertificateFileNamePrefix = "oemcert_";
// File class. The implementation is platform dependent.
class CORE_UTIL_EXPORT File {
@@ -81,6 +79,6 @@ class CORE_UTIL_EXPORT FileSystem {
CORE_DISALLOW_COPY_AND_ASSIGN(FileSystem);
};
} // namespace wvutil
} // namespace wvcdm
#endif // WVCDM_UTIL_FILE_STORE_H_

View File

@@ -5,7 +5,9 @@
#include <string>
#include <vector>
namespace wvutil {
#include "wv_cdm_types.h"
namespace wvcdm {
const char kCurrentDirectory[] = ".";
const char kParentDirectory[] = "..";
@@ -25,4 +27,4 @@ class FileUtils {
static bool CreateDirectory(const std::string& path);
};
} // namespace wvutil
} // namespace wvcdm

View File

@@ -12,10 +12,9 @@
#include <mutex>
#include <string>
#include <vector>
#include "util_common.h"
namespace wvutil {
namespace wvcdm {
// Simple logging class. The implementation is platform dependent.
@@ -53,7 +52,7 @@ class LogBuffer {
extern LogBuffer g_logbuf;
static const uint32_t UNKNOWN_UID = std::numeric_limits<uint32_t>::max();
static const uint32_t UNKNOWN_UID = ~0;
#ifdef __ANDROID__
void SetLoggingUid(const uint32_t);
@@ -93,16 +92,16 @@ CORE_UTIL_EXPORT void Log(const char* file, const char* function, int line,
// Log APIs
#ifndef LOGE
# define LOGE(...) \
Log(__FILE__, __func__, __LINE__, wvutil::LOG_ERROR, __VA_ARGS__)
Log(__FILE__, __func__, __LINE__, wvcdm::LOG_ERROR, __VA_ARGS__)
# define LOGW(...) \
Log(__FILE__, __func__, __LINE__, wvutil::LOG_WARN, __VA_ARGS__)
Log(__FILE__, __func__, __LINE__, wvcdm::LOG_WARN, __VA_ARGS__)
# define LOGI(...) \
Log(__FILE__, __func__, __LINE__, wvutil::LOG_INFO, __VA_ARGS__)
Log(__FILE__, __func__, __LINE__, wvcdm::LOG_INFO, __VA_ARGS__)
# define LOGD(...) \
Log(__FILE__, __func__, __LINE__, wvutil::LOG_DEBUG, __VA_ARGS__)
Log(__FILE__, __func__, __LINE__, wvcdm::LOG_DEBUG, __VA_ARGS__)
# define LOGV(...) \
Log(__FILE__, __func__, __LINE__, wvutil::LOG_VERBOSE, __VA_ARGS__)
Log(__FILE__, __func__, __LINE__, wvcdm::LOG_VERBOSE, __VA_ARGS__)
#endif
} // namespace wvutil
} // namespace wvcdm
#endif // WVCDM_UTIL_LOG_H_

View File

@@ -13,7 +13,7 @@
#include "disallow_copy_and_assign.h"
#include "util_common.h"
namespace wvutil {
namespace wvcdm {
// A simple reader-writer mutex implementation that mimics the one from C++17
class CORE_UTIL_EXPORT shared_mutex {
@@ -60,6 +60,6 @@ class shared_lock {
CORE_DISALLOW_COPY_AND_ASSIGN(shared_lock);
};
} // namespace wvutil
} // namespace wvcdm
#endif // WVCDM_UTIL_RW_LOCK_H_

View File

@@ -12,7 +12,7 @@
#include "util_common.h"
namespace wvutil {
namespace wvcdm {
// ASCII hex to Binary conversion.
CORE_UTIL_EXPORT std::vector<uint8_t> a2b_hex(const std::string& b);
@@ -58,6 +58,6 @@ CORE_UTIL_EXPORT inline int64_t ntohll64(int64_t x) { return htonll64(x); }
// Encode unsigned integer into a big endian formatted string.
CORE_UTIL_EXPORT std::string EncodeUint32(uint32_t u);
} // namespace wvutil
} // namespace wvcdm
#endif // WVCDM_UTIL_STRING_CONVERSIONS_H_

View File

@@ -13,7 +13,7 @@
// This type alias is for convenience.
using CdmRandomLock = std::unique_lock<std::mutex>;
namespace wvutil {
namespace wvcdm {
namespace {
// More information about C++11's random number generators can be found
@@ -77,10 +77,10 @@ std::string CdmRandomGenerator::RandomData(size_t length) {
return std::string();
}
CdmRandomLock lock(generator_lock_);
std::uniform_int_distribution<short> dist(0, 255); // Range of [0, 255].
std::uniform_int_distribution<uint8_t> dist; // Range of [0, 255].
std::string random_data(length, '\0');
std::generate(random_data.begin(), random_data.end(),
[&]() { return static_cast<char>(dist(generator_)); });
[&]() { return dist(generator_); });
return random_data;
}
@@ -104,4 +104,4 @@ CdmRandomGenerator* CdmRandom::GetInstance() {
return g_instance;
}
} // namespace wvutil
} // namespace wvcdm

View File

@@ -8,7 +8,7 @@
#include <sys/time.h>
namespace wvutil {
namespace wvcdm {
int64_t Clock::GetCurrentTime() {
struct timeval tv;
@@ -17,4 +17,4 @@ int64_t Clock::GetCurrentTime() {
return tv.tv_sec;
}
} // namespace wvutil
} // namespace wvcdm

View File

@@ -20,6 +20,7 @@
#include "file_utils.h"
#include "log.h"
#include "string_conversions.h"
#include "wv_cdm_constants.h"
#include <openssl/md5.h>
@@ -27,7 +28,7 @@
// to strerror_r(3).
#define ERRORSTR_BUF_SIZE 1024
namespace wvutil {
namespace wvcdm {
namespace {
// Maximum number of attempts to read or write on a file.
constexpr size_t kMaxIoAttempts = 5;
@@ -41,8 +42,6 @@ constexpr int kClosedFd = -1;
// handling code to enter a bad state.
constexpr int kNoError = 0;
constexpr char kEmptyOrigin[] = "";
// Reads from file specified by |fd| into the provided |buffer| up to
// the number of bytes specified by |count|.
// This is an internal function and assumes that all parameters are
@@ -283,7 +282,7 @@ std::string GetFileNameSafeHash(const std::string& input) {
std::vector<uint8_t> hash(MD5_DIGEST_LENGTH);
MD5(reinterpret_cast<const uint8_t*>(input.data()), input.size(),
hash.data());
return wvutil::Base64SafeEncode(hash);
return wvcdm::Base64SafeEncode(hash);
}
std::string GetFileNameForIdentifier(const std::string path,
@@ -426,7 +425,7 @@ class AndroidFile : public File {
class FileSystem::Impl {};
FileSystem::FileSystem() : FileSystem(kEmptyOrigin, nullptr) {}
FileSystem::FileSystem() : FileSystem(EMPTY_ORIGIN, nullptr) {}
FileSystem::FileSystem(const std::string& origin, void* /* extra_data */)
: origin_(origin) {}
@@ -529,4 +528,4 @@ void FileSystem::set_origin(const std::string& origin) { origin_ = origin; }
void FileSystem::set_identifier(const std::string& identifier) {
identifier_ = identifier;
}
} // namespace wvutil
} // namespace wvcdm

View File

@@ -15,9 +15,11 @@
#include <cstring>
#include "file_store.h"
#include "log.h"
#include "properties.h"
namespace wvutil {
namespace wvcdm {
bool IsCurrentOrParentDirectory(const char* dir) {
return strcmp(dir, kCurrentDirectory) == 0 ||
@@ -226,4 +228,4 @@ bool FileUtils::CreateDirectory(const std::string& path_in) {
return true;
}
} // namespace wvutil
} // namespace wvcdm

View File

@@ -39,7 +39,7 @@
// #define LOG_NDEBUG 0
namespace wvutil {
namespace wvcdm {
namespace {
int64_t GetCurrentTimeMs() {
@@ -141,4 +141,4 @@ std::vector<LogMessage> LogBuffer::getLogs() {
return {buffer_.begin(), buffer_.end()};
}
} // namespace wvutil
} // namespace wvcdm

View File

@@ -6,7 +6,7 @@
#include "log.h"
namespace wvutil {
namespace wvcdm {
shared_mutex::~shared_mutex() {
if (reader_count_ > 0) {
@@ -57,4 +57,4 @@ void shared_mutex::unlock() {
condition_variable_.notify_all();
}
} // namespace wvutil
} // namespace wvcdm

View File

@@ -14,7 +14,7 @@
#include "log.h"
#include "platform.h"
namespace wvutil {
namespace wvcdm {
namespace {
// Base64 character set, indexed for their 6-bit mapping, plus '='.
const char kBase64Codes[] =
@@ -326,4 +326,4 @@ std::string EncodeUint32(unsigned int u) {
return s;
}
} // namespace wvutil
} // namespace wvcdm

View File

@@ -2,14 +2,14 @@
// source code may only be used and distributed under the Widevine License
// Agreement.
#include <gtest/gtest.h>
#include <utility>
#include <gtest/gtest.h>
#include "log.h"
#include "string_conversions.h"
namespace wvutil {
namespace wvcdm {
namespace {
@@ -189,4 +189,4 @@ TEST_F(HtoNLL64Test, NegativeNumber) {
int64_t host_byte_order = htonll64(*network_byte_order);
EXPECT_EQ(-0x01FdFcFbFaF9F8F8, host_byte_order);
}
} // namespace wvutil
} // namespace wvcdm

View File

@@ -2,10 +2,6 @@
// source code may only be used and distributed under the Widevine License
// Agreement.
#include "cdm_random.h"
#include <gmock/gmock.h>
#include <gtest/gtest.h>
#include <stdlib.h>
#include <algorithm>
@@ -16,7 +12,12 @@
#include <type_traits>
#include <vector>
namespace wvutil {
#include <gmock/gmock.h>
#include <gtest/gtest.h>
#include "cdm_random.h"
namespace wvcdm {
namespace {
// Random data vector lengths.
@@ -183,4 +184,4 @@ TEST(CdmRandomTest, AllMethods) {
CdmRandom::RandomBool();
}
} // namespace wvutil
} // namespace wvcdm

View File

@@ -2,15 +2,14 @@
// 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 wvutil {
namespace wvcdm {
namespace {
const std::string kTestDirName = "test_dir";
@@ -32,26 +31,26 @@ class FileTest : public testing::Test {
void TearDown() override { RemoveTestDir(); }
void RemoveTestDir() {
EXPECT_TRUE(file_system_.Remove(wvcdm::test_vectors::kTestDir));
EXPECT_TRUE(file_system_.Remove(test_vectors::kTestDir));
}
FileSystem file_system_;
};
TEST_F(FileTest, FileExists) {
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));
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));
}
TEST_F(FileTest, RemoveDir) {
EXPECT_TRUE(file_system_.Remove(wvcdm::test_vectors::kTestDir));
EXPECT_FALSE(file_system_.Exists(wvcdm::test_vectors::kTestDir));
EXPECT_TRUE(file_system_.Remove(test_vectors::kTestDir));
EXPECT_FALSE(file_system_.Exists(test_vectors::kTestDir));
}
TEST_F(FileTest, OpenFile) {
std::string path = wvcdm::test_vectors::kTestDir + kTestFileName;
std::string path = test_vectors::kTestDir + kTestFileName;
EXPECT_TRUE(file_system_.Remove(path));
std::unique_ptr<File> file = file_system_.Open(path, FileSystem::kCreate);
@@ -61,7 +60,7 @@ TEST_F(FileTest, OpenFile) {
}
TEST_F(FileTest, RemoveDirAndFile) {
std::string path = wvcdm::test_vectors::kTestDir + kTestFileName;
std::string path = test_vectors::kTestDir + kTestFileName;
std::unique_ptr<File> file = file_system_.Open(path, FileSystem::kCreate);
ASSERT_TRUE(file);
@@ -75,15 +74,15 @@ TEST_F(FileTest, RemoveDirAndFile) {
EXPECT_TRUE(file_system_.Exists(path));
RemoveTestDir();
EXPECT_FALSE(file_system_.Exists(wvcdm::test_vectors::kTestDir));
EXPECT_FALSE(file_system_.Exists(test_vectors::kTestDir));
EXPECT_FALSE(file_system_.Exists(path));
}
TEST_F(FileTest, RemoveWildcardFiles) {
std::string path1 = wvcdm::test_vectors::kTestDir + kTestFileName;
std::string path2 = wvcdm::test_vectors::kTestDir + kTestFileName2;
std::string path1 = test_vectors::kTestDir + kTestFileName;
std::string path2 = test_vectors::kTestDir + kTestFileName2;
std::string wildcard_path =
wvcdm::test_vectors::kTestDir + kWildcard + kTestFileNameExt;
test_vectors::kTestDir + kWildcard + kTestFileNameExt;
std::unique_ptr<File> file = file_system_.Open(path1, FileSystem::kCreate);
ASSERT_TRUE(file);
@@ -98,7 +97,7 @@ TEST_F(FileTest, RemoveWildcardFiles) {
}
TEST_F(FileTest, FileSize) {
std::string path = wvcdm::test_vectors::kTestDir + kTestFileName;
std::string path = test_vectors::kTestDir + kTestFileName;
file_system_.Remove(path);
std::string write_data = CdmRandom::RandomData(600);
@@ -112,7 +111,7 @@ TEST_F(FileTest, FileSize) {
}
TEST_F(FileTest, WriteReadBinaryFile) {
std::string path = wvcdm::test_vectors::kTestDir + kTestFileName;
std::string path = test_vectors::kTestDir + kTestFileName;
file_system_.Remove(path);
std::string write_data = CdmRandom::RandomData(600);
@@ -135,10 +134,10 @@ TEST_F(FileTest, ListFiles) {
std::vector<std::string> names;
std::string not_path("zzz");
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::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::unique_ptr<File> file = file_system_.Open(path1, FileSystem::kCreate);
ASSERT_TRUE(file);
@@ -182,7 +181,7 @@ TEST_F(FileTest, ListFiles) {
TEST_F(FileTest, CreateGlobalCertificates) {
// Clear directory
std::vector<std::string> names;
std::string path_dir = wvcdm::test_vectors::kTestDir;
std::string path_dir = test_vectors::kTestDir;
std::string wild_card_path = path_dir + kWildcard;
file_system_.Remove(wild_card_path);
if (file_system_.List(path_dir, &names)) {
@@ -190,10 +189,9 @@ TEST_F(FileTest, CreateGlobalCertificates) {
}
// Create certificates and verify that they exist
std::string certificate_path =
wvcdm::test_vectors::kTestDir + kCertificateFileName;
std::string certificate_path = test_vectors::kTestDir + kCertificateFileName;
std::string legacy_certificate_path =
wvcdm::test_vectors::kTestDir + kLegacyCertificateFileName;
test_vectors::kTestDir + kLegacyCertificateFileName;
std::unique_ptr<File> file =
file_system_.Open(certificate_path, FileSystem::kCreate);
@@ -216,17 +214,16 @@ TEST_F(FileTest, CreateGlobalCertificates) {
TEST_F(FileTest, CreateCertificates) {
// Clear directory
std::vector<std::string> names;
std::string path_dir = wvcdm::test_vectors::kTestDir;
std::string path_dir = 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 =
wvcdm::test_vectors::kTestDir + kCertificateFileName;
std::string certificate_path = test_vectors::kTestDir + kCertificateFileName;
std::string legacy_certificate_path =
wvcdm::test_vectors::kTestDir + kLegacyCertificateFileName;
test_vectors::kTestDir + kLegacyCertificateFileName;
// Create Global certificates
std::unique_ptr<File> file =
@@ -288,17 +285,16 @@ TEST_F(FileTest, CreateCertificates) {
TEST_F(FileTest, RemoveCertificates) {
// Clear directory
std::vector<std::string> names;
std::string path_dir = wvcdm::test_vectors::kTestDir;
std::string path_dir = 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 =
wvcdm::test_vectors::kTestDir + kCertificateFileName;
std::string certificate_path = test_vectors::kTestDir + kCertificateFileName;
std::string legacy_certificate_path =
wvcdm::test_vectors::kTestDir + kLegacyCertificateFileName;
test_vectors::kTestDir + kLegacyCertificateFileName;
// Create Global certificates
std::unique_ptr<File> file =
@@ -334,34 +330,30 @@ 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(wvcdm::test_vectors::kTestDir + names[i]));
EXPECT_TRUE(file_system_.Remove(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(wvcdm::test_vectors::kTestDir + names[i]));
EXPECT_TRUE(file_system_.Exists(test_vectors::kTestDir + names[i]));
} else {
EXPECT_FALSE(
file_system_.Exists(wvcdm::test_vectors::kTestDir + names[i]));
EXPECT_FALSE(file_system_.Exists(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(wvcdm::test_vectors::kTestDir + names[i]));
EXPECT_TRUE(file_system_.Remove(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(wvcdm::test_vectors::kTestDir + names[i]));
EXPECT_FALSE(file_system_.Exists(test_vectors::kTestDir + names[i]));
}
}
} // namespace wvutil
} // namespace wvcdm

View File

@@ -10,7 +10,7 @@
#include "file_store.h"
#include "test_vectors.h"
namespace wvutil {
namespace wvcdm {
namespace {
const std::string kTestDirName = "test_dir";
@@ -31,14 +31,14 @@ class FileUtilsTest : public testing::Test {
virtual void TearDown() { RemoveTestDir(); }
void CreateTestDir() {
if (!file_system_.Exists(wvcdm::test_vectors::kTestDir)) {
EXPECT_TRUE(FileUtils::CreateDirectory(wvcdm::test_vectors::kTestDir));
if (!file_system_.Exists(test_vectors::kTestDir)) {
EXPECT_TRUE(FileUtils::CreateDirectory(test_vectors::kTestDir));
}
EXPECT_TRUE(file_system_.Exists(wvcdm::test_vectors::kTestDir));
EXPECT_TRUE(file_system_.Exists(test_vectors::kTestDir));
}
void RemoveTestDir() {
EXPECT_TRUE(file_system_.Remove(wvcdm::test_vectors::kTestDir));
EXPECT_TRUE(file_system_.Remove(test_vectors::kTestDir));
}
void CreateTestFile(const std::string file_path) {
@@ -63,43 +63,43 @@ class FileUtilsTest : public testing::Test {
};
TEST_F(FileUtilsTest, CreateDirectory) {
std::string dir_wo_delimiter = wvcdm::test_vectors::kTestDir.substr(
0, wvcdm::test_vectors::kTestDir.size() - 1);
std::string dir_wo_delimiter =
test_vectors::kTestDir.substr(0, test_vectors::kTestDir.size() - 1);
if (file_system_.Exists(dir_wo_delimiter))
EXPECT_TRUE(file_system_.Remove(dir_wo_delimiter));
EXPECT_FALSE(file_system_.Exists(dir_wo_delimiter));
EXPECT_TRUE(FileUtils::CreateDirectory(dir_wo_delimiter));
EXPECT_TRUE(file_system_.Exists(dir_wo_delimiter));
EXPECT_TRUE(file_system_.Remove(dir_wo_delimiter));
EXPECT_TRUE(FileUtils::CreateDirectory(wvcdm::test_vectors::kTestDir));
EXPECT_TRUE(file_system_.Exists(wvcdm::test_vectors::kTestDir));
EXPECT_TRUE(file_system_.Remove(wvcdm::test_vectors::kTestDir));
EXPECT_TRUE(FileUtils::CreateDirectory(test_vectors::kTestDir));
EXPECT_TRUE(file_system_.Exists(test_vectors::kTestDir));
EXPECT_TRUE(file_system_.Remove(test_vectors::kTestDir));
}
TEST_F(FileUtilsTest, IsDir) {
std::string path = wvcdm::test_vectors::kTestDir + kTestFileName;
std::string path = test_vectors::kTestDir + kTestFileName;
std::unique_ptr<File> file = file_system_.Open(path, FileSystem::kCreate);
EXPECT_TRUE(file);
EXPECT_TRUE(file_system_.Exists(path));
EXPECT_TRUE(file_system_.Exists(wvcdm::test_vectors::kTestDir));
EXPECT_TRUE(file_system_.Exists(test_vectors::kTestDir));
EXPECT_FALSE(FileUtils::IsDirectory(path));
EXPECT_TRUE(FileUtils::IsDirectory(wvcdm::test_vectors::kTestDir));
EXPECT_TRUE(FileUtils::IsDirectory(test_vectors::kTestDir));
}
TEST_F(FileUtilsTest, IsRegularFile) {
std::string path = wvcdm::test_vectors::kTestDir + kTestFileName;
std::string path = test_vectors::kTestDir + kTestFileName;
std::unique_ptr<File> file = file_system_.Open(path, FileSystem::kCreate);
EXPECT_TRUE(file);
EXPECT_TRUE(file_system_.Exists(path));
EXPECT_TRUE(file_system_.Exists(wvcdm::test_vectors::kTestDir));
EXPECT_TRUE(file_system_.Exists(test_vectors::kTestDir));
EXPECT_TRUE(FileUtils::IsRegularFile(path));
EXPECT_FALSE(FileUtils::IsRegularFile(wvcdm::test_vectors::kTestDir));
EXPECT_FALSE(FileUtils::IsRegularFile(test_vectors::kTestDir));
}
TEST_F(FileUtilsTest, CopyFile) {
std::string path = wvcdm::test_vectors::kTestDir + kTestFileName;
std::string path = test_vectors::kTestDir + kTestFileName;
file_system_.Remove(path);
std::string write_data = GenerateRandomData(600);
@@ -110,7 +110,7 @@ TEST_F(FileUtilsTest, CopyFile) {
write_data_size);
ASSERT_TRUE(file_system_.Exists(path));
std::string path_copy = wvcdm::test_vectors::kTestDir + kTestFileName2;
std::string path_copy = test_vectors::kTestDir + kTestFileName2;
EXPECT_FALSE(file_system_.Exists(path_copy));
EXPECT_TRUE(FileUtils::Copy(path, path_copy));
@@ -127,15 +127,15 @@ TEST_F(FileUtilsTest, CopyFile) {
TEST_F(FileUtilsTest, ListEmptyDirectory) {
std::vector<std::string> files;
EXPECT_TRUE(FileUtils::List(wvcdm::test_vectors::kTestDir, &files));
EXPECT_TRUE(FileUtils::List(test_vectors::kTestDir, &files));
EXPECT_EQ(0u, files.size());
}
TEST_F(FileUtilsTest, ListFiles) {
std::string path = wvcdm::test_vectors::kTestDir + kTestDirName;
std::string path = test_vectors::kTestDir + kTestDirName;
EXPECT_TRUE(FileUtils::CreateDirectory(path));
path = wvcdm::test_vectors::kTestDir + kTestFileName;
path = test_vectors::kTestDir + kTestFileName;
std::string write_data = GenerateRandomData(600);
size_t write_data_size = write_data.size();
std::unique_ptr<File> file = file_system_.Open(path, FileSystem::kCreate);
@@ -143,7 +143,7 @@ TEST_F(FileUtilsTest, ListFiles) {
EXPECT_EQ(file->Write(write_data.data(), write_data_size), write_data_size);
EXPECT_TRUE(file_system_.Exists(path));
path = wvcdm::test_vectors::kTestDir + kTestFileName2;
path = test_vectors::kTestDir + kTestFileName2;
write_data = GenerateRandomData(600);
write_data_size = write_data.size();
file = file_system_.Open(path, FileSystem::kCreate);
@@ -152,7 +152,7 @@ TEST_F(FileUtilsTest, ListFiles) {
EXPECT_TRUE(file_system_.Exists(path));
std::vector<std::string> files;
EXPECT_TRUE(FileUtils::List(wvcdm::test_vectors::kTestDir, &files));
EXPECT_TRUE(FileUtils::List(test_vectors::kTestDir, &files));
EXPECT_EQ(3u, files.size());
for (size_t i = 0; i < files.size(); ++i) {
@@ -162,7 +162,7 @@ TEST_F(FileUtilsTest, ListFiles) {
}
TEST_F(FileUtilsTest, RemoveDirectory) {
std::string path = wvcdm::test_vectors::kTestDir;
std::string path = test_vectors::kTestDir;
EXPECT_TRUE(FileUtils::CreateDirectory(path));
EXPECT_TRUE(FileUtils::Exists(path));
@@ -171,8 +171,8 @@ TEST_F(FileUtilsTest, RemoveDirectory) {
}
TEST_F(FileUtilsTest, RemoveTopLevelDirectory) {
std::string base_path = wvcdm::test_vectors::kTestDir;
std::string sub_dir_path = wvcdm::test_vectors::kTestDir + kTestDirName;
std::string base_path = test_vectors::kTestDir;
std::string sub_dir_path = test_vectors::kTestDir + kTestDirName;
EXPECT_TRUE(FileUtils::CreateDirectory(sub_dir_path));
EXPECT_TRUE(FileUtils::Exists(sub_dir_path));
@@ -191,7 +191,7 @@ TEST_F(FileUtilsTest, RemoveTopLevelDirectory) {
}
TEST_F(FileUtilsTest, RemoveFilesUsingWildcard) {
std::string base_path = wvcdm::test_vectors::kTestDir + kTestDirName;
std::string base_path = test_vectors::kTestDir + kTestDirName;
EXPECT_TRUE(FileUtils::CreateDirectory(base_path));
EXPECT_TRUE(FileUtils::Exists(base_path));
@@ -221,7 +221,7 @@ TEST_F(FileUtilsTest, RemoveFilesUsingWildcard) {
}
TEST_F(FileUtilsTest, RemoveFilesUsingWildcardAndExtension) {
std::string base_path = wvcdm::test_vectors::kTestDir + kTestDirName;
std::string base_path = test_vectors::kTestDir + kTestDirName;
EXPECT_TRUE(FileUtils::CreateDirectory(base_path));
EXPECT_TRUE(FileUtils::Exists(base_path));
@@ -252,7 +252,7 @@ TEST_F(FileUtilsTest, RemoveFilesUsingWildcardAndExtension) {
}
TEST_F(FileUtilsTest, RemoveFilesUsingPrefixAndWildcard) {
std::string base_path = wvcdm::test_vectors::kTestDir + kTestDirName;
std::string base_path = test_vectors::kTestDir + kTestDirName;
EXPECT_TRUE(FileUtils::CreateDirectory(base_path));
EXPECT_TRUE(FileUtils::Exists(base_path));
@@ -283,7 +283,7 @@ TEST_F(FileUtilsTest, RemoveFilesUsingPrefixAndWildcard) {
}
TEST_F(FileUtilsTest, RemoveFilesUsingPrefixWildcardAndExtension) {
std::string base_path = wvcdm::test_vectors::kTestDir + kTestDirName;
std::string base_path = test_vectors::kTestDir + kTestDirName;
EXPECT_TRUE(FileUtils::CreateDirectory(base_path));
EXPECT_TRUE(FileUtils::Exists(base_path));
@@ -314,4 +314,4 @@ TEST_F(FileUtilsTest, RemoveFilesUsingPrefixWildcardAndExtension) {
EXPECT_TRUE(FileUtils::Exists(file_path_with_different_prefix));
}
} // namespace wvutil
} // namespace wvcdm

View File

@@ -4,12 +4,13 @@
//
// Clock - A fake clock just for running tests.
#include "clock.h"
#include <chrono>
#include "clock.h"
#include "test_sleep.h"
namespace wvutil {
namespace wvcdm {
namespace {
// A fake clock that only advances when TestSleep::Sleep is called.
@@ -39,4 +40,4 @@ int64_t Clock::GetCurrentTime() {
return g_fake_clock->now() / 1000;
}
} // namespace wvutil
} // namespace wvcdm

View File

@@ -22,7 +22,7 @@
#include "clock.h"
#include "log.h"
namespace wvutil {
namespace wvcdm {
bool TestSleep::real_sleep_ = true;
TestSleep::CallBack* TestSleep::callback_ = nullptr;
@@ -157,4 +157,4 @@ bool TestSleep::CanChangeSystemTime() {
return false;
#endif
}
} // namespace wvutil
} // namespace wvcdm

View File

@@ -9,7 +9,7 @@
#include <stdint.h>
namespace wvutil {
namespace wvcdm {
class TestSleep {
public:
@@ -70,6 +70,6 @@ class TestSleep {
static int total_clock_rollback_seconds_;
};
} // namespace wvutil
} // namespace wvcdm
#endif // WVCDM_UTIL_TEST_SLEEP_H_