Merge "Created an ArraySize utility function."

This commit is contained in:
Alex Dale
2019-07-23 22:08:39 +00:00
committed by Android (Google) Code Review
5 changed files with 57 additions and 33 deletions

View File

@@ -26,6 +26,7 @@
#include <gtest/gtest.h>
#include "OEMCryptoCENC.h"
#include "arraysize.h"
#include "config_test_env.h"
#include "license_protocol.pb.h"
#include "license_request.h"
@@ -50,8 +51,6 @@ using ::testing::StrictMock;
namespace {
#define N_ELEM(a) (sizeof(a) / sizeof(a[0]))
// HTTP response codes.
const int kHttpOk = 200;
// The following two responses are unused, but left here for human debuggers.
@@ -535,7 +534,7 @@ TEST_P(WvCdmSrmTest, Srm) {
INSTANTIATE_TEST_CASE_P(
Cdm, WvCdmSrmTest,
::testing::Range(&kSrmTestConfiguration[0],
&kSrmTestConfiguration[N_ELEM(kSrmTestConfiguration)]));
&kSrmTestConfiguration[ArraySize(kSrmTestConfiguration)]));
// These parameterized tests validate SRM scenarios described in
// SRM End-to-End Test Plan doc
@@ -585,6 +584,6 @@ TEST_P(WvCdmSrmNotSupportedTest, Srm) {
INSTANTIATE_TEST_CASE_P(
Cdm, WvCdmSrmNotSupportedTest,
::testing::Range(&kSrmNotSupportedTestConfiguration[0],
&kSrmNotSupportedTestConfiguration[N_ELEM(
&kSrmNotSupportedTestConfiguration[ArraySize(
kSrmNotSupportedTestConfiguration)]));
} // namespace wvcdm

View File

@@ -13,6 +13,8 @@
#include <gmock/gmock.h>
#include <gtest/gtest.h>
#include "OEMCryptoCENC.h"
#include "arraysize.h"
#include "cdm_identifier.h"
#include "config_test_env.h"
#include "device_files.h"
@@ -23,7 +25,6 @@
#include "license_request.h"
#include "log.h"
#include "oemcrypto_adapter.h"
#include "OEMCryptoCENC.h"
#include "properties.h"
#include "string_conversions.h"
#include "test_base.h"
@@ -47,8 +48,6 @@ using ::testing::UnorderedElementsAreArray;
namespace {
#define N_ELEM(a) (sizeof(a)/sizeof(a[0]))
// HTTP response codes.
const int kHttpOk = 200;
@@ -3776,7 +3775,7 @@ TEST_F(WvCdmRequestLicenseTest, UsageRemoveAllTest) {
EXPECT_TRUE(handle.DeleteAllUsageInfoForApp(
DeviceFiles::GetUsageInfoFileName(""), &psts));
for (size_t i = 0; i < N_ELEM(usage_info_sub_samples_icp); ++i) {
for (size_t i = 0; i < ArraySize(usage_info_sub_samples_icp); ++i) {
SubSampleInfo* data = usage_info_sub_samples_icp + i;
property_set.set_app_id(i % 2 == 0 ? app_id_empty : app_id_not_empty);
decryptor_->OpenSession(config_.key_system(), &property_set,
@@ -3874,7 +3873,7 @@ TEST_F(WvCdmRequestLicenseTest, RemoveCorruptedUsageInfoTest) {
EXPECT_TRUE(handle.DeleteAllUsageInfoForApp(
DeviceFiles::GetUsageInfoFileName(""), &psts));
for (size_t i = 0; i < N_ELEM(usage_info_sub_samples_icp); ++i) {
for (size_t i = 0; i < ArraySize(usage_info_sub_samples_icp); ++i) {
SubSampleInfo* data = usage_info_sub_samples_icp + i;
property_set.set_app_id(i % 2 == 0 ? app_id_empty : app_id_not_empty);
decryptor_->OpenSession(config_.key_system(), &property_set,
@@ -4020,7 +4019,7 @@ TEST_F(WvCdmRequestLicenseTest, RemoveCorruptedUsageInfoTest2) {
EXPECT_TRUE(handle.DeleteAllUsageInfoForApp(
DeviceFiles::GetUsageInfoFileName(""), &psts));
for (size_t i = 0; i < N_ELEM(usage_info_sub_samples_icp); ++i) {
for (size_t i = 0; i < ArraySize(usage_info_sub_samples_icp); ++i) {
SubSampleInfo* data = usage_info_sub_samples_icp + i;
property_set.set_app_id(i % 2 == 0 ? app_id_empty : app_id_not_empty);
decryptor_->OpenSession(config_.key_system(), &property_set,
@@ -4187,7 +4186,7 @@ TEST_F(WvCdmRequestLicenseTest, GetSecureStopIdsTest) {
EXPECT_TRUE(retrieved_secure_stop_ids.empty());
// First fetch licenses for the default app
for (size_t i = 0; i < N_ELEM(kUsageLicenseTestVector1); ++i) {
for (size_t i = 0; i < ArraySize(kUsageLicenseTestVector1); ++i) {
SubSampleInfo* data = kUsageLicenseTestVector1[i].sub_sample;
property_set.set_app_id(app_id_empty);
@@ -4219,7 +4218,7 @@ TEST_F(WvCdmRequestLicenseTest, GetSecureStopIdsTest) {
// Verify that there are usage records for the default identifier but
// none yet for the non-default one
std::vector<CdmSecureStopId> expected_provider_session_tokens;
for (size_t i = 0; i < N_ELEM(kUsageLicenseTestVector1); ++i) {
for (size_t i = 0; i < ArraySize(kUsageLicenseTestVector1); ++i) {
expected_provider_session_tokens.push_back(
kUsageLicenseTestVector1[i].provider_session_token);
}
@@ -4228,7 +4227,8 @@ TEST_F(WvCdmRequestLicenseTest, GetSecureStopIdsTest) {
NO_ERROR,
decryptor_->GetSecureStopIds(app_id_empty, kDefaultCdmIdentifier,
&retrieved_secure_stop_ids));
EXPECT_EQ(N_ELEM(kUsageLicenseTestVector1), retrieved_secure_stop_ids.size());
EXPECT_EQ(ArraySize(kUsageLicenseTestVector1),
retrieved_secure_stop_ids.size());
EXPECT_THAT(retrieved_secure_stop_ids,
UnorderedElementsAreArray(expected_provider_session_tokens));
@@ -4240,7 +4240,7 @@ TEST_F(WvCdmRequestLicenseTest, GetSecureStopIdsTest) {
EXPECT_TRUE(retrieved_secure_stop_ids.empty());
// Now fetch licenses for the other identifier
for (size_t i = 0; i < N_ELEM(kUsageLicenseTestVector2); ++i) {
for (size_t i = 0; i < ArraySize(kUsageLicenseTestVector2); ++i) {
SubSampleInfo* data = kUsageLicenseTestVector2[i].sub_sample;
property_set.set_app_id(kExampleIdentifier.app_package_name);
@@ -4278,14 +4278,15 @@ TEST_F(WvCdmRequestLicenseTest, GetSecureStopIdsTest) {
decryptor_->GetSecureStopIds(kDefaultCdmIdentifier.app_package_name,
kDefaultCdmIdentifier,
&retrieved_secure_stop_ids));
EXPECT_EQ(N_ELEM(kUsageLicenseTestVector1), retrieved_secure_stop_ids.size());
EXPECT_EQ(ArraySize(kUsageLicenseTestVector1),
retrieved_secure_stop_ids.size());
EXPECT_THAT(retrieved_secure_stop_ids,
UnorderedElementsAreArray(expected_provider_session_tokens));
retrieved_secure_stop_ids.clear();
expected_provider_session_tokens.clear();
for (size_t i = 0; i < N_ELEM(kUsageLicenseTestVector2); ++i) {
for (size_t i = 0; i < ArraySize(kUsageLicenseTestVector2); ++i) {
expected_provider_session_tokens.push_back(
kUsageLicenseTestVector2[i].provider_session_token);
}
@@ -4295,7 +4296,8 @@ TEST_F(WvCdmRequestLicenseTest, GetSecureStopIdsTest) {
decryptor_->GetSecureStopIds(kExampleIdentifier.app_package_name,
kExampleIdentifier,
&retrieved_secure_stop_ids));
EXPECT_EQ(N_ELEM(kUsageLicenseTestVector2), retrieved_secure_stop_ids.size());
EXPECT_EQ(ArraySize(kUsageLicenseTestVector2),
retrieved_secure_stop_ids.size());
EXPECT_THAT(retrieved_secure_stop_ids,
UnorderedElementsAreArray(expected_provider_session_tokens));
@@ -4447,7 +4449,7 @@ TEST_F(WvCdmRequestLicenseTest, UsageRemoveSecureStopTest) {
DeviceFiles::GetUsageInfoFileName(""), &psts));
// First fetch licenses for the default app
for (size_t i = 0; i < N_ELEM(kUsageLicenseTestVector1); ++i) {
for (size_t i = 0; i < ArraySize(kUsageLicenseTestVector1); ++i) {
SubSampleInfo* data = kUsageLicenseTestVector1[i].sub_sample;
property_set.set_app_id(app_id_empty);
@@ -4476,7 +4478,7 @@ TEST_F(WvCdmRequestLicenseTest, UsageRemoveSecureStopTest) {
// Provision and fetch licenses for the other identifier
Provision(kExampleIdentifier, kLevelDefault);
for (size_t i = 0; i < N_ELEM(kUsageLicenseTestVector2); ++i) {
for (size_t i = 0; i < ArraySize(kUsageLicenseTestVector2); ++i) {
SubSampleInfo* data = kUsageLicenseTestVector2[i].sub_sample;
property_set.set_app_id(kExampleIdentifier.app_package_name);
@@ -4513,9 +4515,9 @@ TEST_F(WvCdmRequestLicenseTest, UsageRemoveSecureStopTest) {
NO_ERROR,
decryptor_->GetSecureStopIds(kDefaultCdmIdentifier.app_package_name,
kDefaultCdmIdentifier, &secure_stop_ids));
EXPECT_EQ(N_ELEM(kUsageLicenseTestVector1), secure_stop_ids.size());
EXPECT_EQ(ArraySize(kUsageLicenseTestVector1), secure_stop_ids.size());
for (size_t i = 0; i < N_ELEM(kUsageLicenseTestVector1); ++i) {
for (size_t i = 0; i < ArraySize(kUsageLicenseTestVector1); ++i) {
EXPECT_EQ(
NO_ERROR,
decryptor_->RemoveUsageInfo(kDefaultCdmIdentifier.app_package_name,
@@ -4532,9 +4534,9 @@ TEST_F(WvCdmRequestLicenseTest, UsageRemoveSecureStopTest) {
NO_ERROR,
decryptor_->GetSecureStopIds(kExampleIdentifier.app_package_name,
kExampleIdentifier, &secure_stop_ids));
EXPECT_EQ(N_ELEM(kUsageLicenseTestVector2), secure_stop_ids.size());
EXPECT_EQ(ArraySize(kUsageLicenseTestVector2), secure_stop_ids.size());
for (size_t i = 0; i < N_ELEM(kUsageLicenseTestVector2); ++i) {
for (size_t i = 0; i < ArraySize(kUsageLicenseTestVector2); ++i) {
EXPECT_EQ(
NO_ERROR,
decryptor_->RemoveUsageInfo(kExampleIdentifier.app_package_name,
@@ -5807,7 +5809,7 @@ TEST_P(WvCenc30SwitchCipherModeTest, DecryptionTest) {
CdmKeyStatusMap key_status_map = listener.GetKeyStatusMap();
EXPECT_EQ(8u, key_status_map.size());
for (size_t i = 0; i < N_ELEM(info->sample_info); ++i) {
for (size_t i = 0; i < ArraySize(info->sample_info); ++i) {
Cenc30SampleInfo* data = &info->sample_info[i];
std::vector<uint8_t> output_buffer(data->encrypted_data.size(), 0);
std::vector<uint8_t> iv(data->iv.begin(), data->iv.end());