Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/containers/scoped_ptr_map.h" | 5 #include "base/containers/scoped_ptr_map.h" |
| 6 | 6 |
| 7 #include <functional> | 7 #include <functional> |
| 8 #include <map> | 8 #include <map> |
| 9 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| 11 #include "base/bind.h" | 11 #include "base/bind.h" |
| 12 #include "base/callback.h" | 12 #include "base/callback.h" |
| 13 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
| 14 #include "testing/gtest/include/gtest/gtest.h" | 14 #include "testing/gtest/include/gtest/gtest.h" |
| 15 | 15 |
| 16 namespace base { | 16 namespace base { |
| 17 namespace { | 17 namespace { |
| 18 namespace namespace_with_ignore_result { | |
|
danakj
2015/10/29 17:48:39
ditto
Sam McNally
2015/10/30 00:18:40
Done.
| |
| 19 | |
| 20 class Value {}; | |
| 21 | |
| 22 template <typename T> | |
| 23 void ignore_result(const T&) {} | |
| 24 } | |
| 18 | 25 |
| 19 // A ScopedDestroyer sets a Boolean to true upon destruction. | 26 // A ScopedDestroyer sets a Boolean to true upon destruction. |
| 20 class ScopedDestroyer { | 27 class ScopedDestroyer { |
| 21 public: | 28 public: |
| 22 ScopedDestroyer(bool* destroyed) : destroyed_(destroyed) { | 29 ScopedDestroyer(bool* destroyed) : destroyed_(destroyed) { |
| 23 *destroyed_ = false; | 30 *destroyed_ = false; |
| 24 } | 31 } |
| 25 | 32 |
| 26 ~ScopedDestroyer() { *destroyed_ = true; } | 33 ~ScopedDestroyer() { *destroyed_ = true; } |
| 27 | 34 |
| (...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 244 | 251 |
| 245 ScopedPtrMap<int, scoped_ptr<ScopedDestroyer>> result = callback.Run(); | 252 ScopedPtrMap<int, scoped_ptr<ScopedDestroyer>> result = callback.Run(); |
| 246 EXPECT_TRUE(scoped_map.empty()); | 253 EXPECT_TRUE(scoped_map.empty()); |
| 247 EXPECT_EQ(elem, result.find(0)->second); | 254 EXPECT_EQ(elem, result.find(0)->second); |
| 248 EXPECT_FALSE(destroyed); | 255 EXPECT_FALSE(destroyed); |
| 249 | 256 |
| 250 result.clear(); | 257 result.clear(); |
| 251 EXPECT_TRUE(destroyed); | 258 EXPECT_TRUE(destroyed); |
| 252 }; | 259 }; |
| 253 | 260 |
| 261 // Test that using a value type from a namespace containing an ignore_result | |
| 262 // function compiles correctly. | |
| 263 TEST(ScopedPtrMapTest, IgnoreResultCompile) { | |
| 264 ScopedPtrMap<int, scoped_ptr<namespace_with_ignore_result::Value>> scoped_map; | |
| 265 scoped_map.insert(1, | |
| 266 make_scoped_ptr(new namespace_with_ignore_result::Value)); | |
| 267 } | |
| 268 | |
| 254 } // namespace | 269 } // namespace |
| 255 } // namespace base | 270 } // namespace base |
| OLD | NEW |