blob: f2739fcea6e6380ffdf2f79f53514eb0cb547885 [file] [log] [blame]
license.botbf09a502008-08-24 00:55:551// Copyright (c) 2006-2008 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.
initial.commitd7cae122008-07-26 21:49:384
5#include "testing/gtest/include/gtest/gtest.h"
6#include "base/ref_counted.h"
7
[email protected]935f7762009-01-10 00:53:138namespace {
9
initial.commitd7cae122008-07-26 21:49:3810class SelfAssign : public base::RefCounted<SelfAssign> {
[email protected]877d55d2009-11-05 21:53:0811 friend class base::RefCounted<SelfAssign>;
12
13 ~SelfAssign() {}
initial.commitd7cae122008-07-26 21:49:3814};
15
[email protected]935f7762009-01-10 00:53:1316class CheckDerivedMemberAccess : public scoped_refptr<SelfAssign> {
17 public:
18 CheckDerivedMemberAccess() {
19 // This shouldn't compile if we don't have access to the member variable.
20 SelfAssign** pptr = &ptr_;
21 EXPECT_EQ(*pptr, ptr_);
22 }
23};
24
25} // end namespace
26
initial.commitd7cae122008-07-26 21:49:3827TEST(RefCountedUnitTest, TestSelfAssignment) {
28 SelfAssign* p = new SelfAssign;
29 scoped_refptr<SelfAssign> var = p;
30 var = var;
31 EXPECT_EQ(var.get(), p);
32}
license.botbf09a502008-08-24 00:55:5533
[email protected]935f7762009-01-10 00:53:1334TEST(RefCountedUnitTest, ScopedRefPtrMemberAccess) {
35 CheckDerivedMemberAccess check;
36}