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/bind.h" | 5 #include "base/bind.h" |
6 | 6 |
7 #include "base/callback.h" | 7 #include "base/callback.h" |
8 #include "base/memory/ref_counted.h" | 8 #include "base/memory/ref_counted.h" |
9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
10 #include "base/memory/weak_ptr.h" | 10 #include "base/memory/weak_ptr.h" |
(...skipping 774 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
785 EXPECT_GE(2, copies); | 785 EXPECT_GE(2, copies); |
786 EXPECT_EQ(0, assigns); | 786 EXPECT_EQ(0, assigns); |
787 } | 787 } |
788 | 788 |
789 // Callback construction and assignment tests. | 789 // Callback construction and assignment tests. |
790 // - Construction from an InvokerStorageHolder should not cause ref/deref. | 790 // - Construction from an InvokerStorageHolder should not cause ref/deref. |
791 // - Assignment from other callback should only cause one ref | 791 // - Assignment from other callback should only cause one ref |
792 // | 792 // |
793 // TODO(ajwong): Is there actually a way to test this? | 793 // TODO(ajwong): Is there actually a way to test this? |
794 | 794 |
795 #if defined(OS_WIN) | |
796 int __fastcall FastCallFunc(int n) { | |
797 return n; | |
798 } | |
799 | |
800 int __stdcall StdCallFunc(int n) { | |
801 return n; | |
802 } | |
803 | |
804 // Windows specific calling convention support. | |
805 // - Can bind a __fastcall function. | |
806 // - Can bind a __stdcall function. | |
807 TEST_F(BindTest, WindowsCallingConventions) { | |
808 Callback<int(void)> fastcall_cb = Bind(&FastCallFunc, 1); | |
809 EXPECT_EQ(1, fastcall_cb.Run()); | |
810 | |
811 Callback<int(void)> stdcall_cb = Bind(&StdCallFunc, 2); | |
812 EXPECT_EQ(2, stdcall_cb.Run()); | |
813 } | |
814 #endif | |
815 | |
816 #if (!defined(NDEBUG) || defined(DCHECK_ALWAYS_ON)) && GTEST_HAS_DEATH_TEST | 795 #if (!defined(NDEBUG) || defined(DCHECK_ALWAYS_ON)) && GTEST_HAS_DEATH_TEST |
817 | 796 |
818 // Test null callbacks cause a DCHECK. | 797 // Test null callbacks cause a DCHECK. |
819 TEST(BindDeathTest, NullCallback) { | 798 TEST(BindDeathTest, NullCallback) { |
820 base::Callback<void(int)> null_cb; | 799 base::Callback<void(int)> null_cb; |
821 ASSERT_TRUE(null_cb.is_null()); | 800 ASSERT_TRUE(null_cb.is_null()); |
822 EXPECT_DEATH(base::Bind(null_cb, 42), ""); | 801 EXPECT_DEATH(base::Bind(null_cb, 42), ""); |
823 } | 802 } |
824 | 803 |
825 #endif // (!defined(NDEBUG) || defined(DCHECK_ALWAYS_ON)) && | 804 #endif // (!defined(NDEBUG) || defined(DCHECK_ALWAYS_ON)) && |
826 // GTEST_HAS_DEATH_TEST | 805 // GTEST_HAS_DEATH_TEST |
827 | 806 |
828 } // namespace | 807 } // namespace |
829 } // namespace base | 808 } // namespace base |
OLD | NEW |