Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(967)

Side by Side Diff: net/quic/core/quic_one_block_arena_test.cc

Issue 2848203002: Add a platform implementation of QuicTest and QuicTestWithParam (Closed)
Patch Set: net/quic/platform/impl/quic_test_impl.cc Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « net/quic/core/quic_headers_stream_test.cc ('k') | net/quic/core/quic_packet_creator_test.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2016 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "net/quic/core/quic_one_block_arena.h" 5 #include "net/quic/core/quic_one_block_arena.h"
6 6
7 #include <cstdint> 7 #include <cstdint>
8 8
9 #include "net/quic/platform/api/quic_containers.h" 9 #include "net/quic/platform/api/quic_containers.h"
10 #include "net/quic/platform/api/quic_test.h"
10 #include "net/quic/test_tools/quic_test_utils.h" 11 #include "net/quic/test_tools/quic_test_utils.h"
11 #include "testing/gmock/include/gmock/gmock.h"
12 #include "testing/gtest/include/gtest/gtest.h"
13 12
14 namespace net { 13 namespace net {
15 namespace { 14 namespace {
16 15
17 static const uint32_t kMaxAlign = 8; 16 static const uint32_t kMaxAlign = 8;
18 17
19 struct TestObject { 18 struct TestObject {
20 uint32_t value; 19 uint32_t value;
21 }; 20 };
22 21
23 TEST(QuicOneBlockArenaTest, AllocateSuccess) { 22 class QuicOneBlockArenaTest : public QuicTest {};
23
24 TEST_F(QuicOneBlockArenaTest, AllocateSuccess) {
24 QuicOneBlockArena<1024> arena; 25 QuicOneBlockArena<1024> arena;
25 QuicArenaScopedPtr<TestObject> ptr = arena.New<TestObject>(); 26 QuicArenaScopedPtr<TestObject> ptr = arena.New<TestObject>();
26 EXPECT_TRUE(ptr.is_from_arena()); 27 EXPECT_TRUE(ptr.is_from_arena());
27 } 28 }
28 29
29 TEST(QuicOneBlockArenaTest, Exhaust) { 30 TEST_F(QuicOneBlockArenaTest, Exhaust) {
30 QuicOneBlockArena<1024> arena; 31 QuicOneBlockArena<1024> arena;
31 for (size_t i = 0; i < 1024 / kMaxAlign; ++i) { 32 for (size_t i = 0; i < 1024 / kMaxAlign; ++i) {
32 QuicArenaScopedPtr<TestObject> ptr = arena.New<TestObject>(); 33 QuicArenaScopedPtr<TestObject> ptr = arena.New<TestObject>();
33 EXPECT_TRUE(ptr.is_from_arena()); 34 EXPECT_TRUE(ptr.is_from_arena());
34 } 35 }
35 QuicArenaScopedPtr<TestObject> ptr; 36 QuicArenaScopedPtr<TestObject> ptr;
36 EXPECT_QUIC_BUG(ptr = arena.New<TestObject>(), 37 EXPECT_QUIC_BUG(ptr = arena.New<TestObject>(),
37 "Ran out of space in QuicOneBlockArena"); 38 "Ran out of space in QuicOneBlockArena");
38 EXPECT_FALSE(ptr.is_from_arena()); 39 EXPECT_FALSE(ptr.is_from_arena());
39 } 40 }
40 41
41 TEST(QuicOneBlockArenaTest, NoOverlaps) { 42 TEST_F(QuicOneBlockArenaTest, NoOverlaps) {
42 QuicOneBlockArena<1024> arena; 43 QuicOneBlockArena<1024> arena;
43 std::vector<QuicArenaScopedPtr<TestObject>> objects; 44 std::vector<QuicArenaScopedPtr<TestObject>> objects;
44 QuicIntervalSet<uintptr_t> used; 45 QuicIntervalSet<uintptr_t> used;
45 for (size_t i = 0; i < 1024 / kMaxAlign; ++i) { 46 for (size_t i = 0; i < 1024 / kMaxAlign; ++i) {
46 QuicArenaScopedPtr<TestObject> ptr = arena.New<TestObject>(); 47 QuicArenaScopedPtr<TestObject> ptr = arena.New<TestObject>();
47 EXPECT_TRUE(ptr.is_from_arena()); 48 EXPECT_TRUE(ptr.is_from_arena());
48 49
49 uintptr_t begin = reinterpret_cast<uintptr_t>(ptr.get()); 50 uintptr_t begin = reinterpret_cast<uintptr_t>(ptr.get());
50 uintptr_t end = begin + sizeof(TestObject); 51 uintptr_t end = begin + sizeof(TestObject);
51 EXPECT_FALSE(used.Contains(begin)); 52 EXPECT_FALSE(used.Contains(begin));
52 EXPECT_FALSE(used.Contains(end - 1)); 53 EXPECT_FALSE(used.Contains(end - 1));
53 used.Add(begin, end); 54 used.Add(begin, end);
54 } 55 }
55 } 56 }
56 57
57 } // namespace 58 } // namespace
58 } // namespace net 59 } // namespace net
OLDNEW
« no previous file with comments | « net/quic/core/quic_headers_stream_test.cc ('k') | net/quic/core/quic_packet_creator_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698