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:
Alex Dale
2019-07-15 17:07:23 -07:00
parent 334d966f12
commit 182ca34fca
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