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 <sstream> | 9 #include <sstream> |
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/macros.h" | 13 #include "base/macros.h" |
| 14 #include "build/build_config.h" |
14 #include "testing/gtest/include/gtest/gtest.h" | 15 #include "testing/gtest/include/gtest/gtest.h" |
15 | 16 |
16 namespace { | 17 namespace { |
17 | 18 |
18 // Used to test depth subtyping. | 19 // Used to test depth subtyping. |
19 class ConDecLoggerParent { | 20 class ConDecLoggerParent { |
20 public: | 21 public: |
21 virtual ~ConDecLoggerParent() {} | 22 virtual ~ConDecLoggerParent() {} |
22 | 23 |
23 virtual void SetPtr(int* ptr) = 0; | 24 virtual void SetPtr(int* ptr) = 0; |
(...skipping 370 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
394 | 395 |
395 // Test moving with assignment; | 396 // Test moving with assignment; |
396 scoped_ptr<ConDecLogger> scoper3; | 397 scoped_ptr<ConDecLogger> scoper3; |
397 scoper3 = std::move(scoper2); | 398 scoper3 = std::move(scoper2); |
398 EXPECT_EQ(1, constructed); | 399 EXPECT_EQ(1, constructed); |
399 EXPECT_FALSE(scoper.get()); | 400 EXPECT_FALSE(scoper.get()); |
400 EXPECT_FALSE(scoper2.get()); | 401 EXPECT_FALSE(scoper2.get()); |
401 EXPECT_TRUE(scoper3.get()); | 402 EXPECT_TRUE(scoper3.get()); |
402 } | 403 } |
403 | 404 |
| 405 #if !(defined(OS_LINUX) && !defined(OS_CHROMEOS)) |
404 // Test uncaught Pass() does not have side effects, because Pass() | 406 // Test uncaught Pass() does not have side effects, because Pass() |
405 // is implemented by std::move(). | 407 // is implemented by std::move(). |
406 // TODO(danakj): Remove this test case when we remove Pass(). | 408 // TODO(danakj): Remove this test case when we remove Pass(). |
407 { | 409 { |
408 ConDecLogger* logger = new ConDecLogger(&constructed); | 410 ConDecLogger* logger = new ConDecLogger(&constructed); |
409 scoped_ptr<ConDecLogger> scoper(logger); | 411 scoped_ptr<ConDecLogger> scoper(logger); |
410 EXPECT_EQ(1, constructed); | 412 EXPECT_EQ(1, constructed); |
411 | 413 |
412 // Should auto-destruct logger by end of scope. | 414 // Should auto-destruct logger by end of scope. |
413 scoped_ptr<ConDecLogger>&& rvalue = scoper.Pass(); | 415 scoped_ptr<ConDecLogger>&& rvalue = scoper.Pass(); |
414 // The Pass() function mimics std::move(), which does not have side-effects. | 416 // The Pass() function mimics std::move(), which does not have side-effects. |
415 EXPECT_TRUE(scoper.get()); | 417 EXPECT_TRUE(scoper.get()); |
416 EXPECT_TRUE(rvalue); | 418 EXPECT_TRUE(rvalue); |
417 } | 419 } |
418 EXPECT_EQ(0, constructed); | 420 EXPECT_EQ(0, constructed); |
| 421 #endif |
419 | 422 |
420 // Test that passing to function which does nothing does not leak. | 423 // Test that passing to function which does nothing does not leak. |
421 { | 424 { |
422 ConDecLogger* logger = new ConDecLogger(&constructed); | 425 ConDecLogger* logger = new ConDecLogger(&constructed); |
423 scoped_ptr<ConDecLogger> scoper(logger); | 426 scoped_ptr<ConDecLogger> scoper(logger); |
424 EXPECT_EQ(1, constructed); | 427 EXPECT_EQ(1, constructed); |
425 | 428 |
426 // Should auto-destruct logger by end of scope. | 429 // Should auto-destruct logger by end of scope. |
427 GrabAndDrop(std::move(scoper)); | 430 GrabAndDrop(std::move(scoper)); |
428 EXPECT_FALSE(scoper.get()); | 431 EXPECT_FALSE(scoper.get()); |
(...skipping 401 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
830 EXPECT_FALSE(p < nullptr); | 833 EXPECT_FALSE(p < nullptr); |
831 EXPECT_TRUE(nullptr < p); | 834 EXPECT_TRUE(nullptr < p); |
832 EXPECT_FALSE(pnull < nullptr); | 835 EXPECT_FALSE(pnull < nullptr); |
833 EXPECT_FALSE(nullptr < pnull); | 836 EXPECT_FALSE(nullptr < pnull); |
834 | 837 |
835 EXPECT_FALSE(p <= nullptr); | 838 EXPECT_FALSE(p <= nullptr); |
836 EXPECT_TRUE(nullptr <= p); | 839 EXPECT_TRUE(nullptr <= p); |
837 EXPECT_TRUE(pnull <= nullptr); | 840 EXPECT_TRUE(pnull <= nullptr); |
838 EXPECT_TRUE(nullptr <= pnull); | 841 EXPECT_TRUE(nullptr <= pnull); |
839 } | 842 } |
OLD | NEW |