Home | History | Annotate | Download | only in quic
      1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
      2 // Use of this source code is governed by a BSD-style license that can be
      3 // found in the LICENSE file.
      4 
      5 #include "net/quic/quic_data_writer.h"
      6 
      7 #include "testing/gtest/include/gtest/gtest.h"
      8 
      9 namespace net {
     10 namespace test {
     11 namespace {
     12 
     13 TEST(QuicDataWriterTest, WriteUint8ToOffset) {
     14   QuicDataWriter writer(4);
     15 
     16   writer.WriteUInt32(0xfefdfcfb);
     17   EXPECT_TRUE(writer.WriteUInt8ToOffset(1, 0));
     18   EXPECT_TRUE(writer.WriteUInt8ToOffset(2, 1));
     19   EXPECT_TRUE(writer.WriteUInt8ToOffset(3, 2));
     20   EXPECT_TRUE(writer.WriteUInt8ToOffset(4, 3));
     21 
     22   char* data = writer.take();
     23 
     24   EXPECT_EQ(1, data[0]);
     25   EXPECT_EQ(2, data[1]);
     26   EXPECT_EQ(3, data[2]);
     27   EXPECT_EQ(4, data[3]);
     28 
     29   delete[] data;
     30 }
     31 
     32 TEST(QuicDataWriterDeathTest, WriteUint8ToOffset) {
     33   QuicDataWriter writer(4);
     34 
     35 #if !defined(WIN32) && defined(GTEST_HAS_DEATH_TEST)
     36 #if !defined(DCHECK_ALWAYS_ON)
     37   EXPECT_DEBUG_DEATH(writer.WriteUInt8ToOffset(5, 4), "Check failed");
     38 #else
     39   EXPECT_DEATH(writer.WriteUInt8ToOffset(5, 4), "Check failed");
     40 #endif
     41 #endif
     42 }
     43 
     44 }  // namespace
     45 }  // namespace test
     46 }  // namespace net
     47