Fix -Wshorten-64-to-32 errors in test code

(This is a merge of http://go/wvgerrit/134316.)

This patch fixes code that would trigger -Wshorten-64-to-32 by
implicitly narrowing a variable from 64 to 32 bits. Most of the time, it
does this by making the implicit conversion explicit. Occasionally,
where it makes sense, it does this by expanding the code to operate on a
64-bit value.

This patch removes LicenseKeysTest::NumContentKeys(), which no one was
using, as all the tests access content_key_count_ directly.

Bug: 194971260
Test: x86-64
Change-Id: Iae7685c10b9db989253b349cab693728b438798d
This commit is contained in:
John W. Bruce
2021-11-10 16:16:47 -08:00
parent 0c7db1a836
commit c45559177a
6 changed files with 11 additions and 10 deletions

View File

@@ -207,7 +207,9 @@ class CdmDurationTest : public WvCdmTestBaseWithEngine,
void SleepUntil(uint64_t desired_rental_time) {
const uint64_t rental_time = CurrentRentalTime();
if (desired_rental_time >= rental_time) {
TestSleep::Sleep(desired_rental_time - rental_time);
const unsigned int sleep_time =
static_cast<unsigned int>(desired_rental_time - rental_time);
TestSleep::Sleep(sleep_time);
} else {
LOGW("Test Clock skew sleeping from rental clock time %" PRIu64
" to %" PRIu64,

View File

@@ -73,7 +73,8 @@ class HttpSocketTest : public testing::Test {
// append data
request.append(data);
socket_->WriteAndLogErrors(request.c_str(), request.size(), kTimeout);
socket_->WriteAndLogErrors(request.c_str(),
static_cast<int>(request.size()), kTimeout);
LOGD("request: %s", request.c_str());
return true;

View File

@@ -201,8 +201,6 @@ class LicenseKeysTest : public ::testing::Test {
EXPECT_EQ(key_usage.generic_verify, verify == kKeyFlagTrue);
}
virtual int NumContentKeys() { return content_key_count_; }
virtual void StageContentKeys() {
content_key_count_ = 0;
AddContentKey(ck_sw_crypto, true, KeyContainer::SW_SECURE_CRYPTO);

View File

@@ -809,11 +809,11 @@ std::string MakePSSH(const std::string& serialized_header) {
size_t data_size = serialized_header.size();
size_t atom_size = data_size + system_id_size + 4 * 4;
std::string pssh = EncodeUint32(atom_size);
std::string pssh = EncodeUint32(static_cast<uint32_t>(atom_size));
pssh.append("pssh");
pssh.append(EncodeUint32(version));
pssh.append(system_id);
pssh.append(EncodeUint32(data_size));
pssh.append(EncodeUint32(static_cast<uint32_t>(data_size)));
pssh.append(serialized_header);
return pssh;
}

View File

@@ -203,8 +203,8 @@ bool UrlRequest::PostRequestWithPath(const std::string& path,
request.append(data);
const int ret = socket_.WriteAndLogErrors(request.c_str(), request.size(),
kWriteTimeoutMs);
const int ret = socket_.WriteAndLogErrors(
request.c_str(), static_cast<int>(request.size()), kWriteTimeoutMs);
LOGV("HTTP request: (%zu): %s", request.size(), b2a_hex(request).c_str());
return ret != -1;
}

View File

@@ -3230,7 +3230,7 @@ TEST_P(OEMCryptoLicenseTest, AntiRollbackHardwareRequired) {
TEST_P(OEMCryptoLicenseTest, MinimumKeys) {
const size_t num_keys = GetResourceValue(kMaxKeysPerSession);
ASSERT_LE(num_keys, kMaxNumKeys) << "Test constants need updating.";
license_messages_.set_num_keys(num_keys);
license_messages_.set_num_keys(static_cast<uint32_t>(num_keys));
ASSERT_NO_FATAL_FAILURE(session_.GenerateNonce());
ASSERT_NO_FATAL_FAILURE(license_messages_.SignAndVerifyRequest());
ASSERT_NO_FATAL_FAILURE(license_messages_.CreateDefaultResponse());
@@ -3258,7 +3258,7 @@ void TestMaxKeys(SessionUtil* util, size_t num_keys_per_session) {
new LicenseRoundTrip(sessions[i].get())));
const size_t num_keys =
std::min(max_total_keys - total_keys, num_keys_per_session);
licenses[i]->set_num_keys(num_keys);
licenses[i]->set_num_keys(static_cast<uint32_t>(num_keys));
total_keys += num_keys;
ASSERT_NO_FATAL_FAILURE(sessions[i]->open());
ASSERT_NO_FATAL_FAILURE(util->InstallTestRSAKey(sessions[i].get()));