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

Side by Side Diff: net/quic/core/quic_arena_scoped_ptr_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_alarm_test.cc ('k') | net/quic/core/quic_bandwidth_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_arena_scoped_ptr.h" 5 #include "net/quic/core/quic_arena_scoped_ptr.h"
6 6
7 #include "net/quic/core/quic_one_block_arena.h" 7 #include "net/quic/core/quic_one_block_arena.h"
8 #include "testing/gmock/include/gmock/gmock.h" 8 #include "net/quic/platform/api/quic_test.h"
9 #include "testing/gtest/include/gtest/gtest.h"
10 9
11 namespace net { 10 namespace net {
12 namespace { 11 namespace {
13 12
14 enum class TestParam { kFromHeap, kFromArena }; 13 enum class TestParam { kFromHeap, kFromArena };
15 14
16 struct TestObject { 15 struct TestObject {
17 explicit TestObject(uintptr_t value) : value(value) { buffer.resize(1024); } 16 explicit TestObject(uintptr_t value) : value(value) { buffer.resize(1024); }
18 uintptr_t value; 17 uintptr_t value;
19 18
20 // Ensure that we have a non-trivial destructor that will leak memory if it's 19 // Ensure that we have a non-trivial destructor that will leak memory if it's
21 // not called. 20 // not called.
22 std::vector<char> buffer; 21 std::vector<char> buffer;
23 }; 22 };
24 23
25 class QuicArenaScopedPtrParamTest : public ::testing::TestWithParam<TestParam> { 24 class QuicArenaScopedPtrParamTest : public QuicTestWithParam<TestParam> {
26 protected: 25 protected:
27 QuicArenaScopedPtr<TestObject> CreateObject(uintptr_t value) { 26 QuicArenaScopedPtr<TestObject> CreateObject(uintptr_t value) {
28 QuicArenaScopedPtr<TestObject> ptr; 27 QuicArenaScopedPtr<TestObject> ptr;
29 switch (GetParam()) { 28 switch (GetParam()) {
30 case TestParam::kFromHeap: 29 case TestParam::kFromHeap:
31 ptr = QuicArenaScopedPtr<TestObject>(new TestObject(value)); 30 ptr = QuicArenaScopedPtr<TestObject>(new TestObject(value));
32 CHECK(!ptr.is_from_arena()); 31 CHECK(!ptr.is_from_arena());
33 break; 32 break;
34 case TestParam::kFromArena: 33 case TestParam::kFromArena:
35 ptr = arena_.New<TestObject>(value); 34 ptr = arena_.New<TestObject>(value);
36 CHECK(ptr.is_from_arena()); 35 CHECK(ptr.is_from_arena());
37 break; 36 break;
38 } 37 }
39 return ptr; 38 return ptr;
40 } 39 }
41 40
42 private: 41 private:
43 QuicOneBlockArena<1024> arena_; 42 QuicOneBlockArena<1024> arena_;
44 }; 43 };
45 44
46 INSTANTIATE_TEST_CASE_P(QuicArenaScopedPtrParamTest, 45 INSTANTIATE_TEST_CASE_P(QuicArenaScopedPtrParamTest,
47 QuicArenaScopedPtrParamTest, 46 QuicArenaScopedPtrParamTest,
48 testing::Values(TestParam::kFromHeap, 47 testing::Values(TestParam::kFromHeap,
49 TestParam::kFromArena)); 48 TestParam::kFromArena));
50 49
51 TEST(QuicArenaScopedPtrTest, NullObjects) { 50 TEST_P(QuicArenaScopedPtrParamTest, NullObjects) {
52 QuicArenaScopedPtr<TestObject> def; 51 QuicArenaScopedPtr<TestObject> def;
53 QuicArenaScopedPtr<TestObject> null(nullptr); 52 QuicArenaScopedPtr<TestObject> null(nullptr);
54 EXPECT_EQ(def, null); 53 EXPECT_EQ(def, null);
55 EXPECT_EQ(def, nullptr); 54 EXPECT_EQ(def, nullptr);
56 EXPECT_EQ(null, nullptr); 55 EXPECT_EQ(null, nullptr);
57 } 56 }
58 57
59 TEST(QuicArenaScopedPtrTest, FromArena) { 58 TEST_P(QuicArenaScopedPtrParamTest, FromArena) {
60 QuicOneBlockArena<1024> arena_; 59 QuicOneBlockArena<1024> arena_;
61 EXPECT_TRUE(arena_.New<TestObject>(0).is_from_arena()); 60 EXPECT_TRUE(arena_.New<TestObject>(0).is_from_arena());
62 EXPECT_FALSE( 61 EXPECT_FALSE(
63 QuicArenaScopedPtr<TestObject>(new TestObject(0)).is_from_arena()); 62 QuicArenaScopedPtr<TestObject>(new TestObject(0)).is_from_arena());
64 } 63 }
65 64
66 TEST_P(QuicArenaScopedPtrParamTest, Assign) { 65 TEST_P(QuicArenaScopedPtrParamTest, Assign) {
67 QuicArenaScopedPtr<TestObject> ptr = CreateObject(12345); 66 QuicArenaScopedPtr<TestObject> ptr = CreateObject(12345);
68 ptr = CreateObject(54321); 67 ptr = CreateObject(54321);
69 EXPECT_EQ(54321u, ptr->value); 68 EXPECT_EQ(54321u, ptr->value);
(...skipping 24 matching lines...) Expand all
94 TEST_P(QuicArenaScopedPtrParamTest, Swap) { 93 TEST_P(QuicArenaScopedPtrParamTest, Swap) {
95 QuicArenaScopedPtr<TestObject> ptr1 = CreateObject(12345); 94 QuicArenaScopedPtr<TestObject> ptr1 = CreateObject(12345);
96 QuicArenaScopedPtr<TestObject> ptr2 = CreateObject(54321); 95 QuicArenaScopedPtr<TestObject> ptr2 = CreateObject(54321);
97 ptr1.swap(ptr2); 96 ptr1.swap(ptr2);
98 EXPECT_EQ(12345u, ptr2->value); 97 EXPECT_EQ(12345u, ptr2->value);
99 EXPECT_EQ(54321u, ptr1->value); 98 EXPECT_EQ(54321u, ptr1->value);
100 } 99 }
101 100
102 } // namespace 101 } // namespace
103 } // namespace net 102 } // namespace net
OLDNEW
« no previous file with comments | « net/quic/core/quic_alarm_test.cc ('k') | net/quic/core/quic_bandwidth_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698