Created an ArraySize utility function.
[ Merge of http://go/wvgerrit/82232 ] The new function `ArraySize` will only work for compile-time fixed-length arrays, and will provide compiler errors if the provided argument is not an array. This will replace the commonly used macro `N_ELEM()` which uses `sizeof()`. Test: Linux unittest Bug: 137041745 Change-Id: I0f5c268197a8062a99ccba43c73349e97f66eb02
This commit is contained in:
@@ -2,12 +2,15 @@
|
||||
// source code may only be used and distributed under the Widevine Master
|
||||
// License Agreement.
|
||||
|
||||
#include "device_files.h"
|
||||
|
||||
#include <gmock/gmock.h>
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
#include "device_files.h"
|
||||
#include "arraysize.h"
|
||||
#include "file_store.h"
|
||||
#include "properties.h"
|
||||
#include "string_conversions.h"
|
||||
@@ -2513,8 +2516,7 @@ TEST_F(DeviceFilesTest, UpdateLicenseState) {
|
||||
DeviceFiles device_files(&file_system);
|
||||
EXPECT_TRUE(device_files.Init(kSecurityLevelL1));
|
||||
|
||||
for (size_t i = 0; i < sizeof(license_update_test_data) / sizeof(LicenseInfo);
|
||||
i++) {
|
||||
for (size_t i = 0; i < ArraySize(license_update_test_data); 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()))
|
||||
@@ -2954,7 +2956,7 @@ TEST_P(DeviceFilesUsageInfoTest, RetrieveByProviderSessionToken) {
|
||||
std::string path = device_base_path_ + file_name;
|
||||
|
||||
size_t max_index_by_app_id = 0;
|
||||
for (size_t i = 0; i < sizeof(kUsageInfoTestData) / sizeof(UsageInfo); ++i) {
|
||||
for (size_t i = 0; i < ArraySize(kUsageInfoTestData); ++i) {
|
||||
if (app_id == kUsageInfoTestData[i].app_id) max_index_by_app_id = i;
|
||||
}
|
||||
std::string file_data =
|
||||
@@ -3014,7 +3016,7 @@ TEST_P(DeviceFilesUsageInfoTest, UpdateUsageInfo) {
|
||||
std::vector<std::string> usage_data_fields;
|
||||
|
||||
size_t max_index_by_app_id = 0;
|
||||
for (size_t i = 0; i < sizeof(kUsageInfoTestData) / sizeof(UsageInfo); ++i) {
|
||||
for (size_t i = 0; i < ArraySize(kUsageInfoTestData); ++i) {
|
||||
if (app_id == kUsageInfoTestData[i].app_id) {
|
||||
max_index_by_app_id = i;
|
||||
|
||||
|
||||
@@ -6,8 +6,10 @@
|
||||
|
||||
#include <gmock/gmock.h>
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "arraysize.h"
|
||||
#include "crypto_session.h"
|
||||
#include "device_files.h"
|
||||
#include "file_store.h"
|
||||
@@ -103,8 +105,7 @@ const std::string kLicenseArray[] = {
|
||||
kUsageEntryInfoOfflineLicense2.key_set_id,
|
||||
kUsageEntryInfoOfflineLicense3.key_set_id,
|
||||
};
|
||||
const size_t kLicenseArraySize = sizeof(kLicenseArray)/
|
||||
sizeof(kLicenseArray[0]);
|
||||
const size_t kLicenseArraySize = ArraySize(kLicenseArray);
|
||||
std::vector<std::string> kLicenseList;
|
||||
|
||||
const std::vector<std::string> kEmptyUsageInfoFilesList;
|
||||
@@ -114,8 +115,7 @@ const std::string kUsageInfoFileArray[] = {
|
||||
kUsageEntryInfoSecureStop2.usage_info_file_name,
|
||||
kUsageEntryInfoSecureStop3.usage_info_file_name,
|
||||
};
|
||||
const size_t kUsageInfoFileArraySize = sizeof(kUsageInfoFileArray)/
|
||||
sizeof(kUsageInfoFileArray[0]);
|
||||
const size_t kUsageInfoFileArraySize = ArraySize(kUsageInfoFileArray);
|
||||
std::vector<std::string> kUsageInfoFileList;
|
||||
|
||||
const DeviceFiles::CdmUsageData kCdmUsageData1 = {
|
||||
@@ -322,6 +322,7 @@ class UsageTableHeaderTest : public WvCdmTestBase {
|
||||
// UsageTableHeader will take ownership of the pointer
|
||||
device_files_ = new MockDeviceFiles();
|
||||
crypto_session_ = new MockCryptoSession(&crypto_metrics_);
|
||||
|
||||
usage_table_header_ = new UsageTableHeader();
|
||||
|
||||
// usage_table_header_ object takes ownership of these objects
|
||||
|
||||
Reference in New Issue
Block a user