• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright (c) 2009 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/flip/flip_io_buffer.h"
6 
7 #include "net/base/test_completion_callback.h"
8 #include "net/flip/flip_session.h"
9 #include "net/flip/flip_stream.h"
10 #include "net/socket/socket_test_util.h"
11 #include "testing/platform_test.h"
12 
13 namespace net {
14 
15 class FlipSessionTest : public PlatformTest {
16  public:
17 };
18 
19 // Test the FlipIOBuffer class.
TEST_F(FlipSessionTest,FlipIOBuffer)20 TEST_F(FlipSessionTest, FlipIOBuffer) {
21   std::priority_queue<FlipIOBuffer> queue_;
22   const size_t kQueueSize = 100;
23 
24   // Insert 100 items; pri 100 to 1.
25   for (size_t index = 0; index < kQueueSize; ++index) {
26     FlipIOBuffer buffer(new IOBuffer(), 0, kQueueSize - index, NULL);
27     queue_.push(buffer);
28   }
29 
30   // Insert several priority 0 items last.
31   const size_t kNumDuplicates = 12;
32   IOBufferWithSize* buffers[kNumDuplicates];
33   for (size_t index = 0; index < kNumDuplicates; ++index) {
34     buffers[index] = new IOBufferWithSize(index+1);
35     queue_.push(FlipIOBuffer(buffers[index], buffers[index]->size(), 0, NULL));
36   }
37 
38   EXPECT_EQ(kQueueSize + kNumDuplicates, queue_.size());
39 
40   // Verify the P0 items come out in FIFO order.
41   for (size_t index = 0; index < kNumDuplicates; ++index) {
42     FlipIOBuffer buffer = queue_.top();
43     EXPECT_EQ(0, buffer.priority());
44     EXPECT_EQ(index + 1, buffer.size());
45     queue_.pop();
46   }
47 
48   int priority = 1;
49   while (queue_.size()) {
50     FlipIOBuffer buffer = queue_.top();
51     EXPECT_EQ(priority++, buffer.priority());
52     queue_.pop();
53   }
54 }
55 
56 }  // namespace net
57