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

Unified Diff: net/quic/platform/api/quic_reference_counted_test.cc

Issue 2589983002: Create a QUIC wrapper around scoped_refptr. (Closed)
Patch Set: rm = nullptr Created 4 years 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/platform/api/quic_reference_counted.h ('k') | net/quic/platform/impl/quic_mutex_impl.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/quic/platform/api/quic_reference_counted_test.cc
diff --git a/net/quic/platform/api/quic_reference_counted_test.cc b/net/quic/platform/api/quic_reference_counted_test.cc
new file mode 100644
index 0000000000000000000000000000000000000000..8f46094b6fed6b66fbc9fcb099359d83457fba86
--- /dev/null
+++ b/net/quic/platform/api/quic_reference_counted_test.cc
@@ -0,0 +1,173 @@
+// 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/platform/api/quic_reference_counted.h"
+
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace net {
+namespace test {
+namespace {
+
+class Base : public QuicReferenceCounted {
+ public:
+ explicit Base(bool* destroyed) : destroyed_(destroyed) {
+ *destroyed_ = false;
+ }
+
+ bool destroyed() const { return *destroyed_; }
+
+ protected:
+ ~Base() override { *destroyed_ = true; }
+
+ private:
+ bool* destroyed_;
+};
+
+class Derived : public Base {
+ public:
+ explicit Derived(bool* destroyed) : Base(destroyed) {}
+
+ private:
+ ~Derived() override {}
+};
+
+TEST(QuicReferenceCountedTest, DefaultConstructor) {
+ QuicReferenceCountedPointer<Base> a;
+ EXPECT_EQ(nullptr, a);
+ EXPECT_EQ(nullptr, a.get());
+ EXPECT_FALSE(a);
+}
+
+TEST(QuicReferenceCountedTest, ConstructFromRawPointer) {
+ bool destroyed = false;
+ {
+ QuicReferenceCountedPointer<Base> a(new Base(&destroyed));
+ EXPECT_FALSE(destroyed);
+ }
+ EXPECT_TRUE(destroyed);
+}
+
+TEST(QuicReferenceCountedTest, RawPointerAssignment) {
+ bool destroyed = false;
+ {
+ QuicReferenceCountedPointer<Base> a;
+ Base* rct = new Base(&destroyed);
+ a = rct;
+ EXPECT_FALSE(destroyed);
+ }
+ EXPECT_TRUE(destroyed);
+}
+
+TEST(QuicReferenceCountedTest, PointerCopy) {
+ bool destroyed = false;
+ {
+ QuicReferenceCountedPointer<Base> a(new Base(&destroyed));
+ {
+ QuicReferenceCountedPointer<Base> b(a);
+ EXPECT_EQ(a, b);
+ EXPECT_FALSE(destroyed);
+ }
+ EXPECT_FALSE(destroyed);
+ }
+ EXPECT_TRUE(destroyed);
+}
+
+TEST(QuicReferenceCountedTest, PointerCopyAssignment) {
+ bool destroyed = false;
+ {
+ QuicReferenceCountedPointer<Base> a(new Base(&destroyed));
+ {
+ QuicReferenceCountedPointer<Base> b = a;
+ EXPECT_EQ(a, b);
+ EXPECT_FALSE(destroyed);
+ }
+ EXPECT_FALSE(destroyed);
+ }
+ EXPECT_TRUE(destroyed);
+}
+
+TEST(QuicReferenceCountedTest, PointerCopyFromOtherType) {
+ bool destroyed = false;
+ {
+ QuicReferenceCountedPointer<Derived> a(new Derived(&destroyed));
+ {
+ QuicReferenceCountedPointer<Base> b(a);
+ EXPECT_EQ(a.get(), b.get());
+ EXPECT_FALSE(destroyed);
+ }
+ EXPECT_FALSE(destroyed);
+ }
+ EXPECT_TRUE(destroyed);
+}
+
+TEST(QuicReferenceCountedTest, PointerCopyAssignmentFromOtherType) {
+ bool destroyed = false;
+ {
+ QuicReferenceCountedPointer<Derived> a(new Derived(&destroyed));
+ {
+ QuicReferenceCountedPointer<Base> b = a;
+ EXPECT_EQ(a.get(), b.get());
+ EXPECT_FALSE(destroyed);
+ }
+ EXPECT_FALSE(destroyed);
+ }
+ EXPECT_TRUE(destroyed);
+}
+
+TEST(QuicReferenceCountedTest, PointerMove) {
+ bool destroyed = false;
+ QuicReferenceCountedPointer<Base> a(new Derived(&destroyed));
+ EXPECT_FALSE(destroyed);
+ QuicReferenceCountedPointer<Base> b(std::move(a));
+ EXPECT_FALSE(destroyed);
+ EXPECT_NE(nullptr, b);
+ EXPECT_EQ(nullptr, a); // NOLINT
+
+ b = nullptr;
+ EXPECT_TRUE(destroyed);
+}
+
+TEST(QuicReferenceCountedTest, PointerMoveAssignment) {
+ bool destroyed = false;
+ QuicReferenceCountedPointer<Base> a(new Derived(&destroyed));
+ EXPECT_FALSE(destroyed);
+ QuicReferenceCountedPointer<Base> b = std::move(a);
+ EXPECT_FALSE(destroyed);
+ EXPECT_NE(nullptr, b);
+ EXPECT_EQ(nullptr, a); // NOLINT
+
+ b = nullptr;
+ EXPECT_TRUE(destroyed);
+}
+
+TEST(QuicReferenceCountedTest, PointerMoveFromOtherType) {
+ bool destroyed = false;
+ QuicReferenceCountedPointer<Derived> a(new Derived(&destroyed));
+ EXPECT_FALSE(destroyed);
+ QuicReferenceCountedPointer<Base> b(std::move(a));
+ EXPECT_FALSE(destroyed);
+ EXPECT_NE(nullptr, b);
+ EXPECT_EQ(nullptr, a); // NOLINT
+
+ b = nullptr;
+ EXPECT_TRUE(destroyed);
+}
+
+TEST(QuicReferenceCountedTest, PointerMoveAssignmentFromOtherType) {
+ bool destroyed = false;
+ QuicReferenceCountedPointer<Derived> a(new Derived(&destroyed));
+ EXPECT_FALSE(destroyed);
+ QuicReferenceCountedPointer<Base> b = std::move(a);
+ EXPECT_FALSE(destroyed);
+ EXPECT_NE(nullptr, b);
+ EXPECT_EQ(nullptr, a); // NOLINT
+
+ b = nullptr;
+ EXPECT_TRUE(destroyed);
+}
+
+} // namespace
+} // namespace test
+} // namespace net
« no previous file with comments | « net/quic/platform/api/quic_reference_counted.h ('k') | net/quic/platform/impl/quic_mutex_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698