This source file includes following definitions.
- TEST
- SetUp
- TEST_P
- TEST_P
#include "net/spdy/spdy_frame_builder.h"
#include "net/spdy/spdy_framer.h"
#include "net/spdy/spdy_protocol.h"
#include "testing/platform_test.h"
namespace net {
TEST(SpdyFrameBuilderTestVersionAgnostic, GetWritableBuffer) {
const size_t builder_size = 10;
SpdyFrameBuilder builder(builder_size);
char* writable_buffer = builder.GetWritableBuffer(builder_size);
memset(writable_buffer, ~1, builder_size);
EXPECT_TRUE(builder.Seek(builder_size));
scoped_ptr<SpdyFrame> frame(builder.take());
char expected[builder_size];
memset(expected, ~1, builder_size);
EXPECT_EQ(base::StringPiece(expected, builder_size),
base::StringPiece(frame->data(), builder_size));
}
class SpdyFrameBuilderTest : public ::testing::TestWithParam<SpdyMajorVersion> {
protected:
virtual void SetUp() {
spdy_version_ = GetParam();
}
SpdyMajorVersion spdy_version_;
};
INSTANTIATE_TEST_CASE_P(SpdyFrameBuilderTests,
SpdyFrameBuilderTest,
::testing::Values(SPDY2, SPDY3, SPDY4));
TEST_P(SpdyFrameBuilderTest, RewriteLength) {
SpdyFramer framer(spdy_version_);
SpdySettingsIR settings_ir;
scoped_ptr<SpdyFrame> expected(framer.SerializeSettings(settings_ir));
SpdyFrameBuilder builder(expected->size() + 1);
if (spdy_version_ < 4) {
builder.WriteControlFrameHeader(framer, SETTINGS, 0);
builder.WriteUInt32(0);
} else {
builder.WriteFramePrefix(framer, SETTINGS, 0, 0);
}
EXPECT_TRUE(builder.GetWritableBuffer(1) != NULL);
builder.RewriteLength(framer);
scoped_ptr<SpdyFrame> built(builder.take());
EXPECT_EQ(base::StringPiece(expected->data(), expected->size()),
base::StringPiece(built->data(), expected->size()));
}
TEST_P(SpdyFrameBuilderTest, OverwriteFlags) {
SpdyFramer framer(spdy_version_);
if (spdy_version_ < SPDY4) {
return;
}
SpdyHeadersIR headers_ir(1);
headers_ir.set_end_headers(false);
scoped_ptr<SpdyFrame> expected(framer.SerializeHeaders(headers_ir));
SpdyFrameBuilder builder(expected->size());
builder.WriteFramePrefix(framer, HEADERS, HEADERS_FLAG_END_HEADERS, 1);
builder.OverwriteFlags(framer, 0);
scoped_ptr<SpdyFrame> built(builder.take());
EXPECT_EQ(base::StringPiece(expected->data(), expected->size()),
base::StringPiece(built->data(), built->size()));
}
}