Skip to content

Commit

Permalink
Use base::size rather than arraysize in mojo/.
Browse files Browse the repository at this point in the history
This is purely a mechanical change; there is no intended behavior change.

BUG=837308

Change-Id: I57f7923f0dd3c30f3115ab0b8d52f4038b30d8c6
Reviewed-on: https://chromium-review.googlesource.com/c/1390720
Reviewed-by: John Abd-El-Malek <jam@chromium.org>
Commit-Queue: Avi Drissman <avi@chromium.org>
Cr-Commit-Position: refs/heads/master@{#618964}
  • Loading branch information
Avi Drissman authored and Commit Bot committed Dec 26, 2018
1 parent 70a1fff commit 773f77c
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 28 deletions.
22 changes: 11 additions & 11 deletions mojo/core/data_pipe_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
#include "base/bind.h"
#include "base/location.h"
#include "base/logging.h"
#include "base/macros.h"
#include "base/message_loop/message_loop.h"
#include "base/run_loop.h"
#include "base/stl_util.h"
#include "build/build_config.h"
#include "mojo/core/embedder/embedder.h"
#include "mojo/core/test/mojo_test_base.h"
Expand Down Expand Up @@ -168,7 +168,7 @@ TEST_F(DataPipeTest, Basic) {
int32_t elements[10] = {};
uint32_t num_bytes = 0;

num_bytes = static_cast<uint32_t>(arraysize(elements) * sizeof(elements[0]));
num_bytes = static_cast<uint32_t>(base::size(elements) * sizeof(elements[0]));

elements[0] = 123;
elements[1] = 456;
Expand Down Expand Up @@ -211,7 +211,7 @@ TEST_F(DataPipeTest, CreateAndMaybeTransfer) {
100, // |element_num_bytes|.
0} // |capacity_num_bytes|.
};
for (size_t i = 0; i < arraysize(test_options); i++) {
for (size_t i = 0; i < base::size(test_options); i++) {
MojoHandle producer_handle, consumer_handle;
MojoCreateDataPipeOptions* options = i ? &test_options[i] : nullptr;
ASSERT_EQ(MOJO_RESULT_OK,
Expand All @@ -236,7 +236,7 @@ TEST_F(DataPipeTest, SimpleReadWrite) {
uint32_t num_bytes = 0;

// Try reading; nothing there yet.
num_bytes = static_cast<uint32_t>(arraysize(elements) * sizeof(elements[0]));
num_bytes = static_cast<uint32_t>(base::size(elements) * sizeof(elements[0]));
ASSERT_EQ(MOJO_RESULT_SHOULD_WAIT, ReadData(elements, &num_bytes));

// Query; nothing there yet.
Expand Down Expand Up @@ -874,7 +874,7 @@ TEST_F(DataPipeTest, AllOrNone) {
// Try writing more than the total capacity of the pipe.
uint32_t num_bytes = 20u * sizeof(int32_t);
int32_t buffer[100];
Seq(0, arraysize(buffer), buffer);
Seq(0, base::size(buffer), buffer);
ASSERT_EQ(MOJO_RESULT_OUT_OF_RANGE, WriteData(buffer, &num_bytes, true));

// Should still be empty.
Expand All @@ -884,7 +884,7 @@ TEST_F(DataPipeTest, AllOrNone) {

// Write some data.
num_bytes = 5u * sizeof(int32_t);
Seq(100, arraysize(buffer), buffer);
Seq(100, base::size(buffer), buffer);
ASSERT_EQ(MOJO_RESULT_OK, WriteData(buffer, &num_bytes, true));
ASSERT_EQ(5u * sizeof(int32_t), num_bytes);

Expand All @@ -910,7 +910,7 @@ TEST_F(DataPipeTest, AllOrNone) {
// Try writing more than the available capacity of the pipe, but less than the
// total capacity.
num_bytes = 6u * sizeof(int32_t);
Seq(200, arraysize(buffer), buffer);
Seq(200, base::size(buffer), buffer);
ASSERT_EQ(MOJO_RESULT_OUT_OF_RANGE, WriteData(buffer, &num_bytes, true));

// Try reading too much.
Expand All @@ -927,13 +927,13 @@ TEST_F(DataPipeTest, AllOrNone) {

// Just a little.
num_bytes = 2u * sizeof(int32_t);
Seq(300, arraysize(buffer), buffer);
Seq(300, base::size(buffer), buffer);
ASSERT_EQ(MOJO_RESULT_OK, WriteData(buffer, &num_bytes, true));
ASSERT_EQ(2u * sizeof(int32_t), num_bytes);

// Just right.
num_bytes = 3u * sizeof(int32_t);
Seq(400, arraysize(buffer), buffer);
Seq(400, base::size(buffer), buffer);
ASSERT_EQ(MOJO_RESULT_OK, WriteData(buffer, &num_bytes, true));
ASSERT_EQ(3u * sizeof(int32_t), num_bytes);

Expand Down Expand Up @@ -1029,7 +1029,7 @@ TEST_F(DataPipeTest, AllOrNone) {
// this.)
TEST_F(DataPipeTest, WrapAround) {
unsigned char test_data[1000];
for (size_t i = 0; i < arraysize(test_data); i++)
for (size_t i = 0; i < base::size(test_data); i++)
test_data[i] = static_cast<unsigned char>(i);

const MojoCreateDataPipeOptions options = {
Expand Down Expand Up @@ -1106,7 +1106,7 @@ TEST_F(DataPipeTest, WrapAround) {

// Read as much as possible. We should read 100 bytes.
num_bytes =
static_cast<uint32_t>(arraysize(read_buffer) * sizeof(read_buffer[0]));
static_cast<uint32_t>(base::size(read_buffer) * sizeof(read_buffer[0]));
memset(read_buffer, 0, num_bytes);
ASSERT_EQ(MOJO_RESULT_OK, ReadData(read_buffer, &num_bytes));
ASSERT_EQ(100u, num_bytes);
Expand Down
11 changes: 6 additions & 5 deletions mojo/core/multiprocess_message_pipe_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include "base/logging.h"
#include "base/message_loop/message_loop.h"
#include "base/run_loop.h"
#include "base/stl_util.h"
#include "base/strings/string_split.h"
#include "build/build_config.h"
#include "mojo/core/handle_signals_state.h"
Expand Down Expand Up @@ -270,7 +271,7 @@ DEFINE_TEST_CLIENT_WITH_PIPE(CheckSharedBuffer,
std::string read_buffer(100, '\0');
uint32_t num_bytes = static_cast<uint32_t>(read_buffer.size());
MojoHandle handles[10];
uint32_t num_handlers = arraysize(handles); // Maximum number to receive
uint32_t num_handlers = base::size(handles); // Maximum number to receive
CHECK_EQ(MojoReadMessage(h, &read_buffer[0], &num_bytes, &handles[0],
&num_handlers, MOJO_READ_MESSAGE_FLAG_NONE),
MOJO_RESULT_OK);
Expand Down Expand Up @@ -350,7 +351,7 @@ TEST_F(MultiprocessMessagePipeTest, SharedBufferPassing) {
handles[0] = duplicated_shared_buffer;
ASSERT_EQ(MOJO_RESULT_OK,
MojoWriteMessage(h, &go1[0], static_cast<uint32_t>(go1.size()),
&handles[0], arraysize(handles),
&handles[0], base::size(handles),
MOJO_WRITE_MESSAGE_FLAG_NONE));

// Wait for a message from the child.
Expand Down Expand Up @@ -407,7 +408,7 @@ DEFINE_TEST_CLIENT_WITH_PIPE(CheckPlatformHandleFile,
std::string read_buffer(100, '\0');
uint32_t num_bytes = static_cast<uint32_t>(read_buffer.size());
MojoHandle handles[255]; // Maximum number to receive.
uint32_t num_handlers = arraysize(handles);
uint32_t num_handlers = base::size(handles);

CHECK_EQ(MojoReadMessage(h, &read_buffer[0], &num_bytes, &handles[0],
&num_handlers, MOJO_READ_MESSAGE_FLAG_NONE),
Expand Down Expand Up @@ -503,7 +504,7 @@ DEFINE_TEST_CLIENT_WITH_PIPE(CheckMessagePipe, MultiprocessMessagePipeTest, h) {

// It should have a message pipe.
MojoHandle handles[10];
uint32_t num_handlers = arraysize(handles);
uint32_t num_handlers = base::size(handles);
CHECK_EQ(MojoReadMessage(h, nullptr, nullptr, &handles[0], &num_handlers,
MOJO_READ_MESSAGE_FLAG_NONE),
MOJO_RESULT_OK);
Expand Down Expand Up @@ -619,7 +620,7 @@ DEFINE_TEST_CLIENT_WITH_PIPE(DataPipeConsumer, MultiprocessMessagePipeTest, h) {

// It should have a message pipe.
MojoHandle handles[10];
uint32_t num_handlers = arraysize(handles);
uint32_t num_handlers = base::size(handles);
CHECK_EQ(MojoReadMessage(h, nullptr, nullptr, &handles[0], &num_handlers,
MOJO_READ_MESSAGE_FLAG_NONE),
MOJO_RESULT_OK);
Expand Down
4 changes: 2 additions & 2 deletions mojo/core/shared_buffer_dispatcher_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@

#include <limits>

#include "base/macros.h"
#include "base/memory/platform_shared_memory_region.h"
#include "base/memory/ref_counted.h"
#include "base/memory/writable_shared_memory_region.h"
#include "base/stl_util.h"
#include "mojo/core/dispatcher.h"
#include "mojo/core/platform_shared_memory_mapping.h"
#include "testing/gtest/include/gtest/gtest.h"
Expand Down Expand Up @@ -65,7 +65,7 @@ TEST_F(SharedBufferDispatcherTest, ValidateCreateOptionsValid) {
// Different flags.
MojoCreateSharedBufferFlags flags_values[] = {
MOJO_CREATE_SHARED_BUFFER_FLAG_NONE};
for (size_t i = 0; i < arraysize(flags_values); i++) {
for (size_t i = 0; i < base::size(flags_values); i++) {
const MojoCreateSharedBufferFlags flags = flags_values[i];

// Different capacities (size 1).
Expand Down
5 changes: 3 additions & 2 deletions mojo/public/cpp/base/ref_counted_memory_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "base/stl_util.h"
#include "mojo/public/cpp/base/big_buffer_mojom_traits.h"
#include "mojo/public/cpp/base/ref_counted_memory_mojom_traits.h"
#include "mojo/public/cpp/test_support/test_utils.h"
Expand All @@ -14,7 +15,7 @@ TEST(RefCountedMemoryTest, Data) {
uint8_t data[] = {'a', 'b', 'c', 'd', 'e'};

scoped_refptr<base::RefCountedMemory> in =
new base::RefCountedStaticMemory(&data, arraysize(data));
new base::RefCountedStaticMemory(&data, base::size(data));

scoped_refptr<base::RefCountedMemory> out;
ASSERT_TRUE(
Expand All @@ -28,7 +29,7 @@ TEST(RefCountedMemoryTest, Null) {
// Stuff real data in out to ensure it gets overwritten with a null.
uint8_t data[] = {'a', 'b', 'c', 'd', 'e'};
scoped_refptr<base::RefCountedMemory> out =
new base::RefCountedStaticMemory(&data, arraysize(data));
new base::RefCountedStaticMemory(&data, base::size(data));

scoped_refptr<base::RefCountedMemory> in;
ASSERT_TRUE(
Expand Down
11 changes: 6 additions & 5 deletions mojo/public/cpp/bindings/tests/connector_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include "base/callback_helpers.h"
#include "base/message_loop/message_loop.h"
#include "base/run_loop.h"
#include "base/stl_util.h"
#include "base/threading/thread.h"
#include "base/threading/thread_task_runner_handle.h"
#include "mojo/public/cpp/bindings/message.h"
Expand Down Expand Up @@ -196,15 +197,15 @@ TEST_F(ConnectorTest, Basic_TwoMessages) {
base::ThreadTaskRunnerHandle::Get());

const char* kText[] = {"hello", "world"};
for (size_t i = 0; i < arraysize(kText); ++i) {
for (size_t i = 0; i < base::size(kText); ++i) {
Message message = CreateMessage(kText[i]);
connector0.Accept(&message);
}

MessageAccumulator accumulator;
connector1.set_incoming_receiver(&accumulator);

for (size_t i = 0; i < arraysize(kText); ++i) {
for (size_t i = 0; i < base::size(kText); ++i) {
if (accumulator.IsEmpty()) {
base::RunLoop run_loop;
accumulator.set_closure(run_loop.QuitClosure());
Expand All @@ -228,7 +229,7 @@ TEST_F(ConnectorTest, Basic_TwoMessages_Synchronous) {
base::ThreadTaskRunnerHandle::Get());

const char* kText[] = {"hello", "world"};
for (size_t i = 0; i < arraysize(kText); ++i) {
for (size_t i = 0; i < base::size(kText); ++i) {
Message message = CreateMessage(kText[i]);
connector0.Accept(&message);
}
Expand Down Expand Up @@ -378,15 +379,15 @@ TEST_F(ConnectorTest, WaitForIncomingMessageWithReentrancy) {
base::ThreadTaskRunnerHandle::Get());

const char* kText[] = {"hello", "world"};
for (size_t i = 0; i < arraysize(kText); ++i) {
for (size_t i = 0; i < base::size(kText); ++i) {
Message message = CreateMessage(kText[i]);
connector0.Accept(&message);
}

ReentrantMessageAccumulator accumulator(&connector1);
connector1.set_incoming_receiver(&accumulator);

for (size_t i = 0; i < arraysize(kText); ++i) {
for (size_t i = 0; i < base::size(kText); ++i) {
if (accumulator.IsEmpty()) {
base::RunLoop run_loop;
accumulator.set_closure(run_loop.QuitClosure());
Expand Down
6 changes: 3 additions & 3 deletions mojo/public/cpp/bindings/tests/wtf_types_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
// found in the LICENSE file.

#include "base/bind.h"
#include "base/macros.h"
#include "base/message_loop/message_loop.h"
#include "base/run_loop.h"
#include "base/stl_util.h"
#include "mojo/public/cpp/bindings/binding.h"
#include "mojo/public/cpp/bindings/lib/fixed_buffer.h"
#include "mojo/public/cpp/bindings/lib/serialization.h"
Expand Down Expand Up @@ -219,7 +219,7 @@ TEST_F(WTFTypesTest, SendStringArray) {
// arrs[1] is null.
arrs[2] = ConstructStringArray();

for (size_t i = 0; i < arraysize(arrs); ++i) {
for (size_t i = 0; i < base::size(arrs); ++i) {
base::RunLoop loop;
// Test that a base::Optional<WTF::Vector<WTF::String>> is unchanged after
// the following conversion:
Expand All @@ -245,7 +245,7 @@ TEST_F(WTFTypesTest, SendStringMap) {
// maps[1] is null.
maps[2] = ConstructStringMap();

for (size_t i = 0; i < arraysize(maps); ++i) {
for (size_t i = 0; i < base::size(maps); ++i) {
base::RunLoop loop;
// Test that a base::Optional<WTF::HashMap<WTF::String, WTF::String>> is
// unchanged after the following conversion:
Expand Down

0 comments on commit 773f77c

Please sign in to comment.