diff --git a/base/containers/scoped_ptr_map.h b/base/containers/scoped_ptr_map.h index a4605e3b68877a..622a39d121e8fa 100644 --- a/base/containers/scoped_ptr_map.h +++ b/base/containers/scoped_ptr_map.h @@ -42,9 +42,9 @@ class ScopedPtrMap { ScopedPtrMap() {} ~ScopedPtrMap() { clear(); } - ScopedPtrMap(ScopedPtrMap&& other) { swap(other); } + ScopedPtrMap(ScopedPtrMap&& other) { swap(other); } - ScopedPtrMap& operator=(ScopedPtrMap&& rhs) { + ScopedPtrMap& operator=(ScopedPtrMap&& rhs) { swap(rhs); return *this; } @@ -61,7 +61,7 @@ class ScopedPtrMap { const_iterator begin() const { return data_.begin(); } const_iterator end() const { return data_.end(); } - void swap(ScopedPtrMap& other) { data_.swap(other.data_); } + void swap(ScopedPtrMap& other) { data_.swap(other.data_); } void clear() { STLDeleteValues(&data_); } diff --git a/base/containers/scoped_ptr_map_unittest.cc b/base/containers/scoped_ptr_map_unittest.cc index 46843b3f2529f2..706b2edfb188b2 100644 --- a/base/containers/scoped_ptr_map_unittest.cc +++ b/base/containers/scoped_ptr_map_unittest.cc @@ -147,15 +147,30 @@ TEST(ScopedPtrMapTest, Clear) { TEST(ScopedPtrMapTest, Compare) { // Construct a ScopedPtrMap with a custom comparison function. - bool destroyed = false; - ScopedPtrMap, std::greater> scoped_map; - scoped_map.insert(0, make_scoped_ptr(new ScopedDestroyer(&destroyed))); - scoped_map.insert(1, make_scoped_ptr(new ScopedDestroyer(&destroyed))); + ScopedPtrMap, std::greater> scoped_map1; + scoped_map1.insert(0, make_scoped_ptr(new int(0))); + scoped_map1.insert(1, make_scoped_ptr(new int(0))); - auto it = scoped_map.begin(); + auto it = scoped_map1.begin(); EXPECT_EQ(1, it->first); ++it; EXPECT_EQ(0, it->first); + + // Test the move constructor. + ScopedPtrMap, std::greater> scoped_map2( + scoped_map1.Pass()); + EXPECT_EQ(2u, scoped_map2.size()); + EXPECT_TRUE(scoped_map1.empty()); + + // Test move assignment. + scoped_map1 = scoped_map2.Pass(); + EXPECT_EQ(2u, scoped_map1.size()); + EXPECT_TRUE(scoped_map2.empty()); + + // Test swap. + scoped_map2.swap(scoped_map1); + EXPECT_EQ(2u, scoped_map2.size()); + EXPECT_TRUE(scoped_map1.empty()); } TEST(ScopedPtrMapTest, Scope) {