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

Side by Side Diff: net/quic/quic_arena_scoped_ptr_test.cc

Issue 2193073003: Move shared files in net/quic/ into net/quic/core/ (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: io_thread_unittest.cc Created 4 years, 4 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/quic_arena_scoped_ptr.h ('k') | net/quic/quic_bandwidth.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4 #include "net/quic/quic_arena_scoped_ptr.h"
5
6 #include "net/quic/quic_one_block_arena.h"
7 #include "testing/gmock/include/gmock/gmock.h"
8 #include "testing/gtest/include/gtest/gtest.h"
9
10 namespace net {
11 namespace {
12
13 enum class TestParam { kFromHeap, kFromArena };
14
15 struct TestObject {
16 explicit TestObject(uintptr_t value) : value(value) { buffer.resize(1024); }
17 uintptr_t value;
18
19 // Ensure that we have a non-trivial destructor that will leak memory if it's
20 // not called.
21 std::vector<char> buffer;
22 };
23
24 class QuicArenaScopedPtrParamTest : public ::testing::TestWithParam<TestParam> {
25 protected:
26 QuicArenaScopedPtr<TestObject> CreateObject(uintptr_t value) {
27 QuicArenaScopedPtr<TestObject> ptr;
28 switch (GetParam()) {
29 case TestParam::kFromHeap:
30 ptr = QuicArenaScopedPtr<TestObject>(new TestObject(value));
31 CHECK(!ptr.is_from_arena());
32 break;
33 case TestParam::kFromArena:
34 ptr = arena_.New<TestObject>(value);
35 CHECK(ptr.is_from_arena());
36 break;
37 }
38 return ptr;
39 }
40
41 private:
42 QuicOneBlockArena<1024> arena_;
43 };
44
45 INSTANTIATE_TEST_CASE_P(QuicArenaScopedPtrParamTest,
46 QuicArenaScopedPtrParamTest,
47 testing::Values(TestParam::kFromHeap,
48 TestParam::kFromArena));
49
50 TEST(QuicArenaScopedPtrTest, NullObjects) {
51 QuicArenaScopedPtr<TestObject> def;
52 QuicArenaScopedPtr<TestObject> null(nullptr);
53 EXPECT_EQ(def, null);
54 EXPECT_EQ(def, nullptr);
55 EXPECT_EQ(null, nullptr);
56 }
57
58 TEST(QuicArenaScopedPtrTest, FromArena) {
59 QuicOneBlockArena<1024> arena_;
60 EXPECT_TRUE(arena_.New<TestObject>(0).is_from_arena());
61 EXPECT_FALSE(
62 QuicArenaScopedPtr<TestObject>(new TestObject(0)).is_from_arena());
63 }
64
65 TEST_P(QuicArenaScopedPtrParamTest, Assign) {
66 QuicArenaScopedPtr<TestObject> ptr = CreateObject(12345);
67 ptr = CreateObject(54321);
68 EXPECT_EQ(54321u, ptr->value);
69 }
70
71 TEST_P(QuicArenaScopedPtrParamTest, MoveConstruct) {
72 QuicArenaScopedPtr<TestObject> ptr1 = CreateObject(12345);
73 QuicArenaScopedPtr<TestObject> ptr2(std::move(ptr1));
74 EXPECT_EQ(nullptr, ptr1);
75 EXPECT_EQ(12345u, ptr2->value);
76 }
77
78 TEST_P(QuicArenaScopedPtrParamTest, Accessors) {
79 QuicArenaScopedPtr<TestObject> ptr = CreateObject(12345);
80 EXPECT_EQ(12345u, (*ptr).value);
81 EXPECT_EQ(12345u, ptr->value);
82 // We explicitly want to test that get() returns a valid pointer to the data,
83 // but the call looks redundant.
84 EXPECT_EQ(12345u, ptr.get()->value); // NOLINT
85 }
86
87 TEST_P(QuicArenaScopedPtrParamTest, Reset) {
88 QuicArenaScopedPtr<TestObject> ptr = CreateObject(12345);
89 ptr.reset(new TestObject(54321));
90 EXPECT_EQ(54321u, ptr->value);
91 }
92
93 TEST_P(QuicArenaScopedPtrParamTest, Swap) {
94 QuicArenaScopedPtr<TestObject> ptr1 = CreateObject(12345);
95 QuicArenaScopedPtr<TestObject> ptr2 = CreateObject(54321);
96 ptr1.swap(ptr2);
97 EXPECT_EQ(12345u, ptr2->value);
98 EXPECT_EQ(54321u, ptr1->value);
99 }
100
101 } // namespace
102 } // namespace net
OLDNEW
« no previous file with comments | « net/quic/quic_arena_scoped_ptr.h ('k') | net/quic/quic_bandwidth.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698