Commit c0f770ef authored by Jeremy Roman's avatar Jeremy Roman Committed by Commit Bot

WTF: Remove RefPtrTest.

RefPtr is now scoped_refptr.

Change-Id: Ifdf5832c631254671a664beb185e001476cb9cb5
Reviewed-on: https://chromium-review.googlesource.com/1111900
Commit-Queue: Yuta Kitamura <yutak@chromium.org>
Reviewed-by: default avatarYuta Kitamura <yutak@chromium.org>
Cr-Commit-Position: refs/heads/master@{#569970}
parent 400d32d2
...@@ -318,7 +318,6 @@ jumbo_source_set("wtf_unittests_sources") { ...@@ -318,7 +318,6 @@ jumbo_source_set("wtf_unittests_sources") {
"hash_set_test.cc", "hash_set_test.cc",
"list_hash_set_test.cc", "list_hash_set_test.cc",
"math_extras_test.cc", "math_extras_test.cc",
"ref_ptr_test.cc",
"saturated_arithmetic_test.cc", "saturated_arithmetic_test.cc",
"scoped_logger_test.cc", "scoped_logger_test.cc",
"string_hasher_test.cc", "string_hasher_test.cc",
......
// Copyright 2014 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 "base/memory/scoped_refptr.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/blink/renderer/platform/wtf/ref_counted.h"
#include "third_party/blink/renderer/platform/wtf/text/string_impl.h"
#include "third_party/blink/renderer/platform/wtf/thread_safe_ref_counted.h"
namespace WTF {
namespace {
TEST(RefPtrTest, Basic) {
scoped_refptr<StringImpl> string;
EXPECT_TRUE(!string);
string = StringImpl::Create("test");
EXPECT_TRUE(!!string);
string = nullptr;
EXPECT_TRUE(!string);
}
TEST(RefPtrTest, MoveAssignmentOperator) {
scoped_refptr<StringImpl> a = StringImpl::Create("a");
scoped_refptr<StringImpl> b = StringImpl::Create("b");
b = std::move(a);
EXPECT_TRUE(!!b);
EXPECT_TRUE(!a);
}
class RefCountedClass : public RefCounted<RefCountedClass> {};
TEST(RefPtrTest, ConstObject) {
// This test is only to ensure we force the compilation of a const RefCounted
// object to ensure the generated code compiles.
scoped_refptr<const RefCountedClass> ptr_to_const =
base::AdoptRef(new RefCountedClass());
}
class CustomDeleter;
struct Deleter {
static void Destruct(const CustomDeleter*);
};
class CustomDeleter : public RefCounted<CustomDeleter, Deleter> {
public:
explicit CustomDeleter(bool* deleted) : deleted_(deleted) {}
private:
friend struct Deleter;
~CustomDeleter() = default;
bool* deleted_;
};
void Deleter::Destruct(const CustomDeleter* obj) {
EXPECT_FALSE(*obj->deleted_);
*obj->deleted_ = true;
delete obj;
}
TEST(RefPtrTest, CustomDeleter) {
bool deleted = false;
scoped_refptr<CustomDeleter> obj =
base::AdoptRef(new CustomDeleter(&deleted));
EXPECT_FALSE(deleted);
obj = nullptr;
EXPECT_TRUE(deleted);
}
class CustomDeleterThreadSafe;
struct DeleterThreadSafe {
static void Destruct(const CustomDeleterThreadSafe*);
};
class CustomDeleterThreadSafe
: public ThreadSafeRefCounted<CustomDeleterThreadSafe, DeleterThreadSafe> {
public:
explicit CustomDeleterThreadSafe(bool* deleted) : deleted_(deleted) {}
private:
friend struct DeleterThreadSafe;
~CustomDeleterThreadSafe() = default;
bool* deleted_;
};
void DeleterThreadSafe::Destruct(const CustomDeleterThreadSafe* obj) {
EXPECT_FALSE(*obj->deleted_);
*obj->deleted_ = true;
delete obj;
}
TEST(RefPtrTest, CustomDeleterThreadSafe) {
bool deleted = false;
scoped_refptr<CustomDeleterThreadSafe> obj =
base::AdoptRef(new CustomDeleterThreadSafe(&deleted));
EXPECT_FALSE(deleted);
obj = nullptr;
EXPECT_TRUE(deleted);
}
} // namespace
} // namespace WTF
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment