summaryrefslogtreecommitdiffstats
path: root/third_party/WebKit/Source/wtf/RefPtrTest.cpp
blob: a21b4f76273605f7521da9b7c656d0d1aeffdf1f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
// 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 "wtf/RefPtr.h"

#include "testing/gtest/include/gtest/gtest.h"
#include "wtf/RefCounted.h"
#include "wtf/text/StringImpl.h"

namespace WTF {

TEST(RefPtrTest, Basic)
{
    RefPtr<StringImpl> string;
    EXPECT_TRUE(!string);
    string = StringImpl::create("test");
    EXPECT_TRUE(!!string);
    string.clear();
    EXPECT_TRUE(!string);
}

TEST(RefPtrTest, MoveAssignmentOperator)
{
    RefPtr<StringImpl> a = StringImpl::create("a");
    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.
    RefPtr<const RefCountedClass> ptrToConst = adoptRef(new RefCountedClass());
}


} // namespace WTF