OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "base/memory/scoped_ptr.h" | 5 #include "base/memory/scoped_ptr.h" |
6 | 6 |
7 #include <sstream> | 7 #include <sstream> |
8 | 8 |
9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
11 #include "base/callback.h" | 11 #include "base/callback.h" |
12 #include "base/strings/stringprintf.h" | |
13 #include "testing/gtest/include/gtest/gtest.h" | 12 #include "testing/gtest/include/gtest/gtest.h" |
14 | 13 |
15 namespace { | 14 namespace { |
16 | 15 |
17 // Used to test depth subtyping. | 16 // Used to test depth subtyping. |
18 class ConDecLoggerParent { | 17 class ConDecLoggerParent { |
19 public: | 18 public: |
20 virtual ~ConDecLoggerParent() {} | 19 virtual ~ConDecLoggerParent() {} |
21 | 20 |
22 virtual void SetPtr(int* ptr) = 0; | 21 virtual void SetPtr(int* ptr) = 0; |
(...skipping 656 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
679 }; | 678 }; |
680 scoped_ptr<int> owner(new int); | 679 scoped_ptr<int> owner(new int); |
681 scoped_ptr<int, NoOpDeleter> x(owner.get()); | 680 scoped_ptr<int, NoOpDeleter> x(owner.get()); |
682 x.reset(x.get()); | 681 x.reset(x.get()); |
683 } | 682 } |
684 | 683 |
685 // Logging a scoped_ptr<T> to an ostream shouldn't convert it to a boolean | 684 // Logging a scoped_ptr<T> to an ostream shouldn't convert it to a boolean |
686 // value first. | 685 // value first. |
687 TEST(ScopedPtrTest, LoggingDoesntConvertToBoolean) { | 686 TEST(ScopedPtrTest, LoggingDoesntConvertToBoolean) { |
688 scoped_ptr<int> x(new int); | 687 scoped_ptr<int> x(new int); |
689 std::stringstream s; | 688 std::stringstream s1; |
690 s << x; | 689 s1 << x; |
691 std::string expected = base::StringPrintf("%p", x.get()); | 690 |
692 EXPECT_EQ(expected, s.str()); | 691 std::stringstream s2; |
| 692 s2 << x.get(); |
| 693 |
| 694 EXPECT_EQ(s2.str(), s1.str()); |
693 } | 695 } |
OLD | NEW |