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 <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
| 9 #include <memory> |
9 #include <sstream> | 10 #include <sstream> |
| 11 #include <utility> |
10 | 12 |
11 #include "base/bind.h" | 13 #include "base/bind.h" |
12 #include "base/callback.h" | 14 #include "base/callback.h" |
13 #include "base/macros.h" | 15 #include "base/macros.h" |
14 #include "build/build_config.h" | 16 #include "build/build_config.h" |
15 #include "testing/gtest/include/gtest/gtest.h" | 17 #include "testing/gtest/include/gtest/gtest.h" |
16 | 18 |
17 namespace { | 19 namespace { |
18 | 20 |
19 // Used to test depth subtyping. | 21 // Used to test depth subtyping. |
(...skipping 813 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
833 EXPECT_FALSE(p < nullptr); | 835 EXPECT_FALSE(p < nullptr); |
834 EXPECT_TRUE(nullptr < p); | 836 EXPECT_TRUE(nullptr < p); |
835 EXPECT_FALSE(pnull < nullptr); | 837 EXPECT_FALSE(pnull < nullptr); |
836 EXPECT_FALSE(nullptr < pnull); | 838 EXPECT_FALSE(nullptr < pnull); |
837 | 839 |
838 EXPECT_FALSE(p <= nullptr); | 840 EXPECT_FALSE(p <= nullptr); |
839 EXPECT_TRUE(nullptr <= p); | 841 EXPECT_TRUE(nullptr <= p); |
840 EXPECT_TRUE(pnull <= nullptr); | 842 EXPECT_TRUE(pnull <= nullptr); |
841 EXPECT_TRUE(nullptr <= pnull); | 843 EXPECT_TRUE(nullptr <= pnull); |
842 } | 844 } |
| 845 |
| 846 TEST(ScopedPtrTest, UniquePtrToScopedPtr) { |
| 847 { |
| 848 std::unique_ptr<int> u(new int(8)); |
| 849 scoped_ptr<int> s(std::move(u)); |
| 850 EXPECT_EQ(8, *s); |
| 851 } |
| 852 |
| 853 { |
| 854 std::unique_ptr<int> u(new int(8)); |
| 855 scoped_ptr<int> s; |
| 856 s = std::move(u); |
| 857 EXPECT_EQ(8, *s); |
| 858 } |
| 859 } |
| 860 |
| 861 TEST(ScopedPtrTest, UniquePtrToScopedPtrWithCustomDeleter) { |
| 862 double dummy, dummy2; |
| 863 int deletes = 0; |
| 864 |
| 865 { |
| 866 std::unique_ptr<double, CountingDeleterChild> u( |
| 867 &dummy, CountingDeleterChild(&deletes)); |
| 868 scoped_ptr<double, CountingDeleter> s(std::move(u)); |
| 869 EXPECT_EQ(&dummy, s.get()); |
| 870 } |
| 871 EXPECT_EQ(1, deletes); |
| 872 |
| 873 int deletes2 = 0; |
| 874 { |
| 875 std::unique_ptr<double, CountingDeleterChild> u( |
| 876 &dummy, CountingDeleterChild(&deletes)); |
| 877 scoped_ptr<double, CountingDeleter> s(&dummy2, CountingDeleter(&deletes2)); |
| 878 s = std::move(u); |
| 879 EXPECT_EQ(&dummy, s.get()); |
| 880 } |
| 881 EXPECT_EQ(2, deletes); |
| 882 EXPECT_EQ(1, deletes2); |
| 883 } |
| 884 |
| 885 TEST(ScopedPtrTest, ScopedPtrToUniquePtr) { |
| 886 { |
| 887 scoped_ptr<int> s(new int(9)); |
| 888 std::unique_ptr<int> u(std::move(s)); |
| 889 EXPECT_EQ(9, *u); |
| 890 } |
| 891 |
| 892 { |
| 893 scoped_ptr<int> s(new int(9)); |
| 894 std::unique_ptr<int> u; |
| 895 u = std::move(s); |
| 896 EXPECT_EQ(9, *u); |
| 897 } |
| 898 } |
| 899 |
| 900 TEST(ScopedPtrTest, ScopedPtrToUniquePtrWithCustomDeleter) { |
| 901 double dummy, dummy2; |
| 902 int deletes = 0; |
| 903 |
| 904 { |
| 905 scoped_ptr<double, CountingDeleterChild> s(&dummy, |
| 906 CountingDeleterChild(&deletes)); |
| 907 std::unique_ptr<double, CountingDeleter> u(std::move(s)); |
| 908 EXPECT_EQ(&dummy, u.get()); |
| 909 } |
| 910 EXPECT_EQ(1, deletes); |
| 911 |
| 912 int deletes2 = 0; |
| 913 { |
| 914 scoped_ptr<double, CountingDeleterChild> s(&dummy, |
| 915 CountingDeleterChild(&deletes)); |
| 916 std::unique_ptr<double, CountingDeleter> u(&dummy2, |
| 917 CountingDeleter(&deletes2)); |
| 918 u = std::move(s); |
| 919 EXPECT_EQ(&dummy, u.get()); |
| 920 } |
| 921 EXPECT_EQ(2, deletes); |
| 922 EXPECT_EQ(1, deletes2); |
| 923 } |
OLD | NEW |