1 // 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.
8 #include "base/linked_ptr.h"
10 #include "base/string_util.h"
11 #include "testing/gtest/include/gtest/gtest.h"
19 // Class which tracks allocation/deallocation
21 A(): mynum(num
++) { history
+= StringPrintf("A%d ctor\n", mynum
); }
22 virtual ~A() { history
+= StringPrintf("A%d dtor\n", mynum
); }
23 virtual void Use() { history
+= StringPrintf("A%d use\n", mynum
); }
29 B() { history
+= StringPrintf("B%d ctor\n", mynum
); }
30 ~B() { history
+= StringPrintf("B%d dtor\n", mynum
); }
31 virtual void Use() { history
+= StringPrintf("B%d use\n", mynum
); }
36 TEST(LinkedPtrTest
, Test
) {
38 linked_ptr
<A
> a0
, a1
, a2
;
41 ASSERT_EQ(a0
.get(), static_cast<A
*>(NULL
));
42 ASSERT_EQ(a1
.get(), static_cast<A
*>(NULL
));
43 ASSERT_EQ(a2
.get(), static_cast<A
*>(NULL
));
44 ASSERT_TRUE(a0
== NULL
);
45 ASSERT_TRUE(a1
== NULL
);
46 ASSERT_TRUE(a2
== NULL
);
49 linked_ptr
<A
> a3(new A
);
51 ASSERT_TRUE(a0
== a3
);
52 ASSERT_TRUE(a0
!= NULL
);
53 ASSERT_TRUE(a0
.get() == a3
);
54 ASSERT_TRUE(a0
== a3
.get());
57 linked_ptr
<A
> a5(new A
);
58 ASSERT_TRUE(a5
.get() != a3
);
59 ASSERT_TRUE(a5
!= a3
.get());
61 linked_ptr
<B
> b0(new B
);
63 ASSERT_TRUE(b0
== a6
);
64 ASSERT_TRUE(a6
== b0
);
65 ASSERT_TRUE(b0
!= NULL
);