Commit 9f54e0e2 authored by Victor Vasiliev's avatar Victor Vasiliev Committed by Commit Bot

Introduce SPDY_ARRAYSIZE into SPDY platform in order to remove discrepancies with google3

Merge internal change: 217614033

R=rch@chromium.org

Change-Id: I98840145bf0ce13e165e17acac196fb92af6f7af
Reviewed-on: https://chromium-review.googlesource.com/c/1288849
Commit-Queue: Victor Vasiliev <vasilvv@chromium.org>
Reviewed-by: default avatarRyan Hamilton <rch@chromium.org>
Cr-Commit-Position: refs/heads/master@{#600918}
parent fabbd969
......@@ -1636,6 +1636,7 @@ component("net") {
"third_party/spdy/core/spdy_protocol.h",
"third_party/spdy/core/write_scheduler.h",
"third_party/spdy/core/zero_copy_output_buffer.h",
"third_party/spdy/platform/api/spdy_arraysize.h",
"third_party/spdy/platform/api/spdy_estimate_memory_usage.h",
"third_party/spdy/platform/api/spdy_export.h",
"third_party/spdy/platform/api/spdy_flags.h",
......@@ -1644,6 +1645,7 @@ component("net") {
"third_party/spdy/platform/api/spdy_string.h",
"third_party/spdy/platform/api/spdy_string_piece.h",
"third_party/spdy/platform/api/spdy_string_utils.h",
"third_party/spdy/platform/impl/spdy_arraysize_impl.h",
"third_party/spdy/platform/impl/spdy_estimate_memory_usage_impl.h",
"third_party/spdy/platform/impl/spdy_export_impl.h",
"third_party/spdy/platform/impl/spdy_flags_impl.cc",
......
......@@ -11,6 +11,7 @@
#include "base/memory/singleton.h"
#include "net/third_party/spdy/core/hpack/hpack_huffman_table.h"
#include "net/third_party/spdy/core/hpack/hpack_static_table.h"
#include "net/third_party/spdy/platform/api/spdy_arraysize.h"
#include "net/third_party/spdy/platform/api/spdy_ptr_util.h"
namespace spdy {
......@@ -327,13 +328,13 @@ std::vector<HpackHuffmanSymbol> HpackHuffmanCode() {
{0xfffffffcul, 30, 256}, // EOS 11111111|11111111|11111111|111111
};
return std::vector<HpackHuffmanSymbol>(
kHpackHuffmanCode, kHpackHuffmanCode + arraysize(kHpackHuffmanCode));
kHpackHuffmanCode, kHpackHuffmanCode + SPDY_ARRAYSIZE(kHpackHuffmanCode));
}
// The "constructor" for a HpackStaticEntry that computes the lengths at
// compile time.
#define STATIC_ENTRY(name, value) \
{ name, arraysize(name) - 1, value, arraysize(value) - 1 }
{ name, SPDY_ARRAYSIZE(name) - 1, value, SPDY_ARRAYSIZE(value) - 1 }
std::vector<HpackStaticEntry> HpackStaticTableVector() {
static const HpackStaticEntry kHpackStaticTable[] = {
......@@ -400,7 +401,7 @@ std::vector<HpackStaticEntry> HpackStaticTableVector() {
STATIC_ENTRY("www-authenticate", ""), // 61
};
return std::vector<HpackStaticEntry>(
kHpackStaticTable, kHpackStaticTable + arraysize(kHpackStaticTable));
kHpackStaticTable, kHpackStaticTable + SPDY_ARRAYSIZE(kHpackStaticTable));
}
#undef STATIC_ENTRY
......
......@@ -22,6 +22,7 @@
#include "net/third_party/spdy/core/hpack/hpack_encoder.h"
#include "net/third_party/spdy/core/hpack/hpack_output_stream.h"
#include "net/third_party/spdy/core/spdy_test_utils.h"
#include "net/third_party/spdy/platform/api/spdy_arraysize.h"
#include "net/third_party/spdy/platform/api/spdy_string.h"
#include "net/third_party/spdy/platform/api/spdy_string_utils.h"
#include "testing/gmock/include/gmock/gmock.h"
......@@ -586,8 +587,8 @@ TEST_P(HpackDecoderAdapterTest, LiteralHeaderNoIndexing) {
// First header with indexed name, second header with string literal
// name.
const char input[] = "\x04\x0c/sample/path\x00\x06:path2\x0e/sample/path/2";
const SpdyHeaderBlock& header_set =
DecodeBlockExpectingSuccess(SpdyStringPiece(input, arraysize(input) - 1));
const SpdyHeaderBlock& header_set = DecodeBlockExpectingSuccess(
SpdyStringPiece(input, SPDY_ARRAYSIZE(input) - 1));
SpdyHeaderBlock expected_header_set;
expected_header_set[":path"] = "/sample/path";
......@@ -599,8 +600,8 @@ TEST_P(HpackDecoderAdapterTest, LiteralHeaderNoIndexing) {
// indexing and string literal names should work.
TEST_P(HpackDecoderAdapterTest, LiteralHeaderIncrementalIndexing) {
const char input[] = "\x44\x0c/sample/path\x40\x06:path2\x0e/sample/path/2";
const SpdyHeaderBlock& header_set =
DecodeBlockExpectingSuccess(SpdyStringPiece(input, arraysize(input) - 1));
const SpdyHeaderBlock& header_set = DecodeBlockExpectingSuccess(
SpdyStringPiece(input, SPDY_ARRAYSIZE(input) - 1));
SpdyHeaderBlock expected_header_set;
expected_header_set[":path"] = "/sample/path";
......
......@@ -14,6 +14,7 @@
#include "net/third_party/http2/hpack/huffman/hpack_huffman_decoder.h"
#include "net/third_party/spdy/core/hpack/hpack_constants.h"
#include "net/third_party/spdy/core/hpack/hpack_output_stream.h"
#include "net/third_party/spdy/platform/api/spdy_arraysize.h"
#include "net/third_party/spdy/platform/api/spdy_string_utils.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
......@@ -84,7 +85,7 @@ TEST_F(GenericHuffmanTableTest, InitializeEdgeCases) {
{bits32("11000000000000000000000000000000"), 3, 6},
{bits32("11100000000000000000000000000000"), 8, 7}};
HpackHuffmanTable table;
EXPECT_TRUE(table.Initialize(code, arraysize(code)));
EXPECT_TRUE(table.Initialize(code, SPDY_ARRAYSIZE(code)));
}
{
// But using 2 bits with one symbol overflows the code.
......@@ -98,7 +99,7 @@ TEST_F(GenericHuffmanTableTest, InitializeEdgeCases) {
{bits32("11100000000000000000000000000000"), 3, 6},
{bits32("00000000000000000000000000000000"), 8, 7}}; // Overflow.
HpackHuffmanTable table;
EXPECT_FALSE(table.Initialize(code, arraysize(code)));
EXPECT_FALSE(table.Initialize(code, SPDY_ARRAYSIZE(code)));
EXPECT_EQ(7, HpackHuffmanTablePeer(table).failed_symbol_id());
}
{
......@@ -109,7 +110,7 @@ TEST_F(GenericHuffmanTableTest, InitializeEdgeCases) {
{bits32("11000000000000000000000000000000"), 3, 2},
{bits32("11100000000000000000000000000000"), 8, 3}};
HpackHuffmanTable table;
EXPECT_TRUE(table.Initialize(code, arraysize(code)));
EXPECT_TRUE(table.Initialize(code, SPDY_ARRAYSIZE(code)));
}
{
// But repeating a length overflows the code.
......@@ -119,7 +120,7 @@ TEST_F(GenericHuffmanTableTest, InitializeEdgeCases) {
{bits32("11000000000000000000000000000000"), 2, 2},
{bits32("00000000000000000000000000000000"), 8, 3}}; // Overflow.
HpackHuffmanTable table;
EXPECT_FALSE(table.Initialize(code, arraysize(code)));
EXPECT_FALSE(table.Initialize(code, SPDY_ARRAYSIZE(code)));
EXPECT_EQ(3, HpackHuffmanTablePeer(table).failed_symbol_id());
}
{
......@@ -130,7 +131,7 @@ TEST_F(GenericHuffmanTableTest, InitializeEdgeCases) {
{bits32("11000000000000000000000000000000"), 3, 1}, // Repeat.
{bits32("11100000000000000000000000000000"), 8, 3}};
HpackHuffmanTable table;
EXPECT_FALSE(table.Initialize(code, arraysize(code)));
EXPECT_FALSE(table.Initialize(code, SPDY_ARRAYSIZE(code)));
EXPECT_EQ(2, HpackHuffmanTablePeer(table).failed_symbol_id());
}
{
......@@ -141,7 +142,7 @@ TEST_F(GenericHuffmanTableTest, InitializeEdgeCases) {
{bits32("10100000000000000000000000000000"), 4, 2},
{bits32("10110000000000000000000000000000"), 8, 3}};
HpackHuffmanTable table;
EXPECT_FALSE(table.Initialize(code, arraysize(code)));
EXPECT_FALSE(table.Initialize(code, SPDY_ARRAYSIZE(code)));
EXPECT_EQ(0, HpackHuffmanTablePeer(table).failed_symbol_id());
}
{
......@@ -152,7 +153,7 @@ TEST_F(GenericHuffmanTableTest, InitializeEdgeCases) {
{bits32("11000000000000000000000000000000"), 2, 2}, // Not canonical.
{bits32("10000000000000000000000000000000"), 8, 3}};
HpackHuffmanTable table;
EXPECT_FALSE(table.Initialize(code, arraysize(code)));
EXPECT_FALSE(table.Initialize(code, SPDY_ARRAYSIZE(code)));
EXPECT_EQ(2, HpackHuffmanTablePeer(table).failed_symbol_id());
}
{
......@@ -163,7 +164,7 @@ TEST_F(GenericHuffmanTableTest, InitializeEdgeCases) {
{bits32("11000000000000000000000000000000"), 3, 2},
{bits32("11100000000000000000000000000000"), 7, 3}};
HpackHuffmanTable table;
EXPECT_FALSE(table.Initialize(code, arraysize(code)));
EXPECT_FALSE(table.Initialize(code, SPDY_ARRAYSIZE(code)));
}
}
......@@ -177,10 +178,10 @@ TEST_F(GenericHuffmanTableTest, ValidateInternalsWithSmallCode) {
{bits32("10001000000000000000000000000000"), 5, 5}, // 6th.
{bits32("10011000000000000000000000000000"), 8, 6}, // 8th.
{bits32("10010000000000000000000000000000"), 5, 7}}; // 7th.
EXPECT_TRUE(table_.Initialize(code, arraysize(code)));
ASSERT_EQ(arraysize(code), peer_.code_by_id().size());
ASSERT_EQ(arraysize(code), peer_.length_by_id().size());
for (size_t i = 0; i < arraysize(code); ++i) {
EXPECT_TRUE(table_.Initialize(code, SPDY_ARRAYSIZE(code)));
ASSERT_EQ(SPDY_ARRAYSIZE(code), peer_.code_by_id().size());
ASSERT_EQ(SPDY_ARRAYSIZE(code), peer_.length_by_id().size());
for (size_t i = 0; i < SPDY_ARRAYSIZE(code); ++i) {
EXPECT_EQ(code[i].code, peer_.code_by_id()[i]);
EXPECT_EQ(code[i].length, peer_.length_by_id()[i]);
}
......@@ -188,11 +189,11 @@ TEST_F(GenericHuffmanTableTest, ValidateInternalsWithSmallCode) {
EXPECT_EQ(bits8("10011000"), peer_.pad_bits());
char input_storage[] = {2, 3, 2, 7, 4};
SpdyStringPiece input(input_storage, arraysize(input_storage));
SpdyStringPiece input(input_storage, SPDY_ARRAYSIZE(input_storage));
// By symbol: (2) 00 (3) 010 (2) 00 (7) 10010 (4) 10000 (6 as pad) 1001100.
char expect_storage[] = {bits8("00010001"), bits8("00101000"),
bits8("01001100")};
SpdyStringPiece expect(expect_storage, arraysize(expect_storage));
SpdyStringPiece expect(expect_storage, SPDY_ARRAYSIZE(expect_storage));
EXPECT_EQ(expect, EncodeString(input));
}
......@@ -231,7 +232,7 @@ TEST_F(HpackHuffmanTableTest, SpecRequestExamples) {
"custom-value",
};
// Round-trip each test example.
for (size_t i = 0; i != arraysize(test_table); i += 2) {
for (size_t i = 0; i != SPDY_ARRAYSIZE(test_table); i += 2) {
const SpdyString& encodedFixture(test_table[i]);
const SpdyString& decodedFixture(test_table[i + 1]);
DecodeString(encodedFixture, &buffer);
......@@ -260,7 +261,7 @@ TEST_F(HpackHuffmanTableTest, SpecResponseExamples) {
"foo=ASDJKHQKBZXOQWEOPIUAXQWEOIU; max-age=3600; version=1",
};
// Round-trip each test example.
for (size_t i = 0; i != arraysize(test_table); i += 2) {
for (size_t i = 0; i != SPDY_ARRAYSIZE(test_table); i += 2) {
const SpdyString& encodedFixture(test_table[i]);
const SpdyString& decodedFixture(test_table[i + 1]);
DecodeString(encodedFixture, &buffer);
......@@ -274,7 +275,7 @@ TEST_F(HpackHuffmanTableTest, RoundTripIndividualSymbols) {
for (size_t i = 0; i != 256; i++) {
char c = static_cast<char>(i);
char storage[3] = {c, c, c};
SpdyStringPiece input(storage, arraysize(storage));
SpdyStringPiece input(storage, SPDY_ARRAYSIZE(storage));
SpdyString buffer_in = EncodeString(input);
SpdyString buffer_out;
DecodeString(buffer_in, &buffer_out);
......@@ -288,7 +289,7 @@ TEST_F(HpackHuffmanTableTest, RoundTripSymbolSequence) {
storage[i] = static_cast<char>(i);
storage[511 - i] = static_cast<char>(i);
}
SpdyStringPiece input(storage, arraysize(storage));
SpdyStringPiece input(storage, SPDY_ARRAYSIZE(storage));
SpdyString buffer_in = EncodeString(input);
SpdyString buffer_out;
......@@ -308,12 +309,12 @@ TEST_F(HpackHuffmanTableTest, EncodedSizeAgreesWithEncodeString) {
};
for (size_t i = 0; i != 256; ++i) {
// Expand last |test_table| entry to cover all codes.
test_table[arraysize(test_table) - 1][i] = static_cast<char>(i);
test_table[SPDY_ARRAYSIZE(test_table) - 1][i] = static_cast<char>(i);
}
HpackOutputStream output_stream;
SpdyString encoding;
for (size_t i = 0; i != arraysize(test_table); ++i) {
for (size_t i = 0; i != SPDY_ARRAYSIZE(test_table); ++i) {
table_.EncodeString(test_table[i], &output_stream);
output_stream.TakeString(&encoding);
EXPECT_EQ(encoding.size(), table_.EncodedSize(test_table[i]));
......
......@@ -9,6 +9,7 @@
#include <memory>
#include "base/sys_byteorder.h"
#include "net/third_party/spdy/platform/api/spdy_arraysize.h"
#include "testing/platform_test.h"
namespace spdy {
......@@ -40,7 +41,7 @@ TEST(SpdyFrameReaderTest, ReadUInt32) {
};
SpdyFrameReader frame_reader(reinterpret_cast<const char*>(kFrameData),
arraysize(kFrameData) * sizeof(uint32_t));
SPDY_ARRAYSIZE(kFrameData) * sizeof(uint32_t));
EXPECT_FALSE(frame_reader.IsDoneReading());
uint32_t uint32_val;
......@@ -63,7 +64,7 @@ TEST(SpdyFrameReaderTest, ReadStringPiece16) {
0x20, 0x31, 0x2c, 0x20, 0x32, 0x2c, 0x20, 0x33, // "Testing, 1, 2, 3"
};
SpdyFrameReader frame_reader(kFrameData, arraysize(kFrameData));
SpdyFrameReader frame_reader(kFrameData, SPDY_ARRAYSIZE(kFrameData));
EXPECT_FALSE(frame_reader.IsDoneReading());
SpdyStringPiece stringpiece_val;
......@@ -86,7 +87,7 @@ TEST(SpdyFrameReaderTest, ReadStringPiece32) {
0x20, 0x34, 0x2c, 0x20, 0x35, 0x2c, 0x20, 0x36, // "Testing, 4, 5, 6"
};
SpdyFrameReader frame_reader(kFrameData, arraysize(kFrameData));
SpdyFrameReader frame_reader(kFrameData, SPDY_ARRAYSIZE(kFrameData));
EXPECT_FALSE(frame_reader.IsDoneReading());
SpdyStringPiece stringpiece_val;
......@@ -105,7 +106,7 @@ TEST(SpdyFrameReaderTest, ReadUInt16WithBufferTooSmall) {
0x00, // part of a uint16_t
};
SpdyFrameReader frame_reader(kFrameData, arraysize(kFrameData));
SpdyFrameReader frame_reader(kFrameData, SPDY_ARRAYSIZE(kFrameData));
EXPECT_FALSE(frame_reader.IsDoneReading());
uint16_t uint16_val;
......@@ -118,7 +119,7 @@ TEST(SpdyFrameReaderTest, ReadUInt32WithBufferTooSmall) {
0x00, 0x00, 0x00, // part of a uint32_t
};
SpdyFrameReader frame_reader(kFrameData, arraysize(kFrameData));
SpdyFrameReader frame_reader(kFrameData, SPDY_ARRAYSIZE(kFrameData));
EXPECT_FALSE(frame_reader.IsDoneReading());
uint32_t uint32_val;
......@@ -138,7 +139,7 @@ TEST(SpdyFrameReaderTest, ReadStringPiece16WithBufferTooSmall) {
0x48, 0x69, // "Hi"
};
SpdyFrameReader frame_reader(kFrameData, arraysize(kFrameData));
SpdyFrameReader frame_reader(kFrameData, SPDY_ARRAYSIZE(kFrameData));
EXPECT_FALSE(frame_reader.IsDoneReading());
SpdyStringPiece stringpiece_val;
......@@ -157,7 +158,7 @@ TEST(SpdyFrameReaderTest, ReadStringPiece16WithBufferWayTooSmall) {
0x00, // part of a uint16_t
};
SpdyFrameReader frame_reader(kFrameData, arraysize(kFrameData));
SpdyFrameReader frame_reader(kFrameData, SPDY_ARRAYSIZE(kFrameData));
EXPECT_FALSE(frame_reader.IsDoneReading());
SpdyStringPiece stringpiece_val;
......@@ -177,7 +178,7 @@ TEST(SpdyFrameReaderTest, ReadStringPiece32WithBufferTooSmall) {
0x48, 0x69, // "Hi"
};
SpdyFrameReader frame_reader(kFrameData, arraysize(kFrameData));
SpdyFrameReader frame_reader(kFrameData, SPDY_ARRAYSIZE(kFrameData));
EXPECT_FALSE(frame_reader.IsDoneReading());
SpdyStringPiece stringpiece_val;
......@@ -196,7 +197,7 @@ TEST(SpdyFrameReaderTest, ReadStringPiece32WithBufferWayTooSmall) {
0x00, 0x00, 0x00, // part of a uint32_t
};
SpdyFrameReader frame_reader(kFrameData, arraysize(kFrameData));
SpdyFrameReader frame_reader(kFrameData, SPDY_ARRAYSIZE(kFrameData));
EXPECT_FALSE(frame_reader.IsDoneReading());
SpdyStringPiece stringpiece_val;
......@@ -215,18 +216,18 @@ TEST(SpdyFrameReaderTest, ReadBytes) {
0x48, 0x69, // "Hi"
};
SpdyFrameReader frame_reader(kFrameData, arraysize(kFrameData));
SpdyFrameReader frame_reader(kFrameData, SPDY_ARRAYSIZE(kFrameData));
EXPECT_FALSE(frame_reader.IsDoneReading());
char dest1[3] = {};
EXPECT_TRUE(frame_reader.ReadBytes(&dest1, arraysize(dest1)));
EXPECT_TRUE(frame_reader.ReadBytes(&dest1, SPDY_ARRAYSIZE(dest1)));
EXPECT_FALSE(frame_reader.IsDoneReading());
EXPECT_EQ("foo", SpdyStringPiece(dest1, arraysize(dest1)));
EXPECT_EQ("foo", SpdyStringPiece(dest1, SPDY_ARRAYSIZE(dest1)));
char dest2[2] = {};
EXPECT_TRUE(frame_reader.ReadBytes(&dest2, arraysize(dest2)));
EXPECT_TRUE(frame_reader.ReadBytes(&dest2, SPDY_ARRAYSIZE(dest2)));
EXPECT_TRUE(frame_reader.IsDoneReading());
EXPECT_EQ("Hi", SpdyStringPiece(dest2, arraysize(dest2)));
EXPECT_EQ("Hi", SpdyStringPiece(dest2, SPDY_ARRAYSIZE(dest2)));
}
TEST(SpdyFrameReaderTest, ReadBytesWithBufferTooSmall) {
......@@ -235,11 +236,11 @@ TEST(SpdyFrameReaderTest, ReadBytesWithBufferTooSmall) {
0x01,
};
SpdyFrameReader frame_reader(kFrameData, arraysize(kFrameData));
SpdyFrameReader frame_reader(kFrameData, SPDY_ARRAYSIZE(kFrameData));
EXPECT_FALSE(frame_reader.IsDoneReading());
char dest[arraysize(kFrameData) + 2] = {};
EXPECT_FALSE(frame_reader.ReadBytes(&dest, arraysize(kFrameData) + 1));
char dest[SPDY_ARRAYSIZE(kFrameData) + 2] = {};
EXPECT_FALSE(frame_reader.ReadBytes(&dest, SPDY_ARRAYSIZE(kFrameData) + 1));
EXPECT_STREQ("", dest);
}
......
#ifndef NET_THIRD_PARTY_SPDY_PLATFORM_API_SPDY_ARRAYSIZE_H_
#define NET_THIRD_PARTY_SPDY_PLATFORM_API_SPDY_ARRAYSIZE_H_
#include "net/third_party/spdy/platform/impl/spdy_arraysize_impl.h"
#define SPDY_ARRAYSIZE(x) SPDY_ARRAYSIZE_IMPL(x)
#endif // NET_THIRD_PARTY_SPDY_PLATFORM_API_SPDY_ARRAYSIZE_H_
#ifndef NET_THIRD_PARTY_SPDY_PLATFORM_IMPL_SPDY_ARRAYSIZE_IMPL_H_
#define NET_THIRD_PARTY_SPDY_PLATFORM_IMPL_SPDY_ARRAYSIZE_IMPL_H_
#include "base/macros.h"
#define SPDY_ARRAYSIZE_IMPL(x) arraysize(x)
#endif /* NET_THIRD_PARTY_SPDY_PLATFORM_IMPL_SPDY_ARRAYSIZE_IMPL_H_ */
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment