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

Unified Diff: net/quic/quic_arena_scoped_ptr_test.cc

Issue 1572353002: QuicAlarms are now allocated out of an arena in QuicConnection (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Merge recent changes. Created 4 years, 11 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « net/quic/quic_arena_scoped_ptr.h ('k') | net/quic/quic_chromium_connection_helper.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/quic/quic_arena_scoped_ptr_test.cc
diff --git a/net/quic/quic_arena_scoped_ptr_test.cc b/net/quic/quic_arena_scoped_ptr_test.cc
new file mode 100644
index 0000000000000000000000000000000000000000..d9ce1b15752aef14ccdb7bd4e8cfffafd122e631
--- /dev/null
+++ b/net/quic/quic_arena_scoped_ptr_test.cc
@@ -0,0 +1,107 @@
+// Copyright (c) 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+#include "net/quic/quic_arena_scoped_ptr.h"
+
+#include "net/quic/quic_one_block_arena.h"
+#include "testing/gmock/include/gmock/gmock.h"
+#include "testing/gtest/include/gtest/gtest.h"
+// #include "testing/base/public/gunit.h"
+
+namespace net {
+namespace {
+
+enum class TestParam { kFromHeap, kFromArena };
+
+struct TestObject {
+ explicit TestObject(uintptr_t value) : value(value) { buffer.resize(1024); }
+ uintptr_t value;
+
+ // Ensure that we have a non-trivial destructor that will leak memory if it's
+ // not called.
+ std::vector<char> buffer;
+};
+
+class QuicArenaScopedPtrParamTest : public ::testing::TestWithParam<TestParam> {
+ protected:
+ QuicArenaScopedPtrParamTest() { FLAGS_quic_enable_arena_allocation = true; }
+
+ QuicArenaScopedPtr<TestObject> CreateObject(uintptr_t value) {
+ QuicArenaScopedPtr<TestObject> ptr;
+ switch (GetParam()) {
+ case TestParam::kFromHeap:
+ ptr = QuicArenaScopedPtr<TestObject>(new TestObject(value));
+ CHECK(!ptr.is_from_arena());
+ break;
+ case TestParam::kFromArena:
+ ptr = arena_.New<TestObject>(value);
+ CHECK(ptr.is_from_arena());
+ break;
+ }
+ return ptr;
+ }
+
+ private:
+ QuicOneBlockArena<1024> arena_;
+};
+
+INSTANTIATE_TEST_CASE_P(QuicArenaScopedPtrParamTest,
+ QuicArenaScopedPtrParamTest,
+ testing::Values(TestParam::kFromHeap,
+ TestParam::kFromArena));
+
+TEST(QuicArenaScopedPtrTest, NullObjects) {
+ FLAGS_quic_enable_arena_allocation = true;
+ QuicArenaScopedPtr<TestObject> def;
+ QuicArenaScopedPtr<TestObject> null(nullptr);
+ EXPECT_EQ(def, null);
+ EXPECT_EQ(def, nullptr);
+ EXPECT_EQ(null, nullptr);
+}
+
+TEST(QuicArenaScopedPtrTest, FromArena) {
+ FLAGS_quic_enable_arena_allocation = true;
+ QuicOneBlockArena<1024> arena_;
+ EXPECT_TRUE(arena_.New<TestObject>(0).is_from_arena());
+ EXPECT_FALSE(
+ QuicArenaScopedPtr<TestObject>(new TestObject(0)).is_from_arena());
+}
+
+TEST_P(QuicArenaScopedPtrParamTest, Assign) {
+ QuicArenaScopedPtr<TestObject> ptr = CreateObject(12345);
+ ptr = CreateObject(54321);
+ EXPECT_EQ(54321u, ptr->value);
+}
+
+TEST_P(QuicArenaScopedPtrParamTest, MoveConstruct) {
+ QuicArenaScopedPtr<TestObject> ptr1 = CreateObject(12345);
+ QuicArenaScopedPtr<TestObject> ptr2(std::move(ptr1));
+ EXPECT_EQ(nullptr, ptr1);
+ EXPECT_EQ(12345u, ptr2->value);
+}
+
+TEST_P(QuicArenaScopedPtrParamTest, Accessors) {
+ QuicArenaScopedPtr<TestObject> ptr = CreateObject(12345);
+ EXPECT_EQ(12345u, (*ptr).value);
+ EXPECT_EQ(12345u, ptr->value);
+ // We explicitly want to test that get() returns a valid pointer to the data,
+ // but the call looks redundant.
+ EXPECT_EQ(12345u, ptr.get()->value); // NOLINT
+}
+
+TEST_P(QuicArenaScopedPtrParamTest, Reset) {
+ QuicArenaScopedPtr<TestObject> ptr = CreateObject(12345);
+ ptr.reset(new TestObject(54321));
+ EXPECT_EQ(54321u, ptr->value);
+}
+
+TEST_P(QuicArenaScopedPtrParamTest, Swap) {
+ QuicArenaScopedPtr<TestObject> ptr1 = CreateObject(12345);
+ QuicArenaScopedPtr<TestObject> ptr2 = CreateObject(54321);
+ ptr1.swap(ptr2);
+ EXPECT_EQ(12345u, ptr2->value);
+ EXPECT_EQ(54321u, ptr1->value);
+}
+
+} // namespace
+} // namespace net
« no previous file with comments | « net/quic/quic_arena_scoped_ptr.h ('k') | net/quic/quic_chromium_connection_helper.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698