From c074a54a4f5256cc33c6556c68b0c2a3b989e250 Mon Sep 17 00:00:00 2001 From: "maruel@chromium.org" Date: Wed, 13 May 2009 15:46:34 +0000 Subject: Remove the explicit keyword from the ScopedComPtr constructor so it can be included in a STL container. Review URL: http://codereview.chromium.org/115247 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@15958 0039d316-1c4b-4281-b951-d872f2087c98 --- base/scoped_comptr_win_unittest.cc | 45 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) (limited to 'base/scoped_comptr_win_unittest.cc') diff --git a/base/scoped_comptr_win_unittest.cc b/base/scoped_comptr_win_unittest.cc index 5e4ad3d..e6d6c68 100644 --- a/base/scoped_comptr_win_unittest.cc +++ b/base/scoped_comptr_win_unittest.cc @@ -5,8 +5,26 @@ #include #include "base/scoped_comptr_win.h" +#include "base/scoped_ptr.h" #include "testing/gtest/include/gtest/gtest.h" +namespace { + +struct Dummy { + Dummy() : adds(0), releases(0) { } + void AddRef() { ++adds; } + void Release() { ++releases; } + + int adds; + int releases; +}; + +extern const IID dummy_iid; +const IID dummy_iid = { 0x12345678u, 0x1234u, 0x5678u, 01, 23, 45, 67, 89, + 01, 23, 45 }; + +} // namespace + TEST(ScopedComPtrTest, ScopedComPtr) { EXPECT_TRUE(memcmp(&ScopedComPtr::iid(), &IID_IUnknown, sizeof(IID)) == 0); @@ -50,3 +68,30 @@ TEST(ScopedComPtrTest, ScopedComPtr) { ::CoUninitialize(); } + +TEST(ScopedComPtrTest, ScopedComPtrVector) { + // Verify we don't get error C2558. + typedef ScopedComPtr Ptr; + std::vector bleh; + scoped_ptr p(new Dummy); + { + Ptr p2(p.get()); + EXPECT_EQ(p->adds, 1); + EXPECT_EQ(p->releases, 0); + Ptr p3 = p2; + EXPECT_EQ(p->adds, 2); + EXPECT_EQ(p->releases, 0); + p3 = p2; + EXPECT_EQ(p->adds, 3); + EXPECT_EQ(p->releases, 1); + bleh.push_back(p2); + EXPECT_EQ(p->adds, 5); + EXPECT_EQ(p->releases, 2); + EXPECT_EQ(bleh[0], p.get()); + bleh.pop_back(); + EXPECT_EQ(p->adds, 5); + EXPECT_EQ(p->releases, 3); + } + EXPECT_EQ(p->adds, 5); + EXPECT_EQ(p->releases, 5); +} -- cgit v1.1