Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3101)

Unified Diff: base/win/scoped_comptr_unittest.cc

Issue 11050009: Use ScopedCOMInitializer in more places. While this doesn't always simplify code, it does mean we … (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: base/win/scoped_comptr_unittest.cc
===================================================================
--- base/win/scoped_comptr_unittest.cc (revision 159813)
+++ base/win/scoped_comptr_unittest.cc (working copy)
@@ -7,6 +7,7 @@
#include <shlobj.h>
#include "base/memory/scoped_ptr.h"
+#include "base/win/scoped_com_initializer.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace base {
@@ -33,50 +34,47 @@
EXPECT_TRUE(memcmp(&ScopedComPtr<IUnknown>::iid(), &IID_IUnknown,
sizeof(IID)) == 0);
- EXPECT_TRUE(SUCCEEDED(::CoInitialize(NULL)));
+ base::win::ScopedCOMInitializer com_initializer;
+ EXPECT_TRUE(com_initializer.succeeded());
- {
- ScopedComPtr<IUnknown> unk;
- EXPECT_TRUE(SUCCEEDED(unk.CreateInstance(CLSID_ShellLink)));
- ScopedComPtr<IUnknown> unk2;
- unk2.Attach(unk.Detach());
- EXPECT_TRUE(unk == NULL);
- EXPECT_TRUE(unk2 != NULL);
+ ScopedComPtr<IUnknown> unk;
+ EXPECT_TRUE(SUCCEEDED(unk.CreateInstance(CLSID_ShellLink)));
+ ScopedComPtr<IUnknown> unk2;
+ unk2.Attach(unk.Detach());
+ EXPECT_TRUE(unk == NULL);
+ EXPECT_TRUE(unk2 != NULL);
- ScopedComPtr<IMalloc> mem_alloc;
- EXPECT_TRUE(SUCCEEDED(CoGetMalloc(1, mem_alloc.Receive())));
+ ScopedComPtr<IMalloc> mem_alloc;
+ EXPECT_TRUE(SUCCEEDED(CoGetMalloc(1, mem_alloc.Receive())));
- ScopedComPtr<IUnknown> qi_test;
- EXPECT_HRESULT_SUCCEEDED(mem_alloc.QueryInterface(IID_IUnknown,
- reinterpret_cast<void**>(qi_test.Receive())));
- EXPECT_TRUE(qi_test.get() != NULL);
- qi_test.Release();
+ ScopedComPtr<IUnknown> qi_test;
+ EXPECT_HRESULT_SUCCEEDED(mem_alloc.QueryInterface(IID_IUnknown,
+ reinterpret_cast<void**>(qi_test.Receive())));
+ EXPECT_TRUE(qi_test.get() != NULL);
+ qi_test.Release();
- // test ScopedComPtr& constructor
- ScopedComPtr<IMalloc> copy1(mem_alloc);
- EXPECT_TRUE(copy1.IsSameObject(mem_alloc));
- EXPECT_FALSE(copy1.IsSameObject(unk2)); // unk2 is valid but different
- EXPECT_FALSE(copy1.IsSameObject(unk)); // unk is NULL
+ // test ScopedComPtr& constructor
+ ScopedComPtr<IMalloc> copy1(mem_alloc);
+ EXPECT_TRUE(copy1.IsSameObject(mem_alloc));
+ EXPECT_FALSE(copy1.IsSameObject(unk2)); // unk2 is valid but different
+ EXPECT_FALSE(copy1.IsSameObject(unk)); // unk is NULL
- IMalloc* naked_copy = copy1.Detach();
- copy1 = naked_copy; // Test the =(T*) operator.
- naked_copy->Release();
+ IMalloc* naked_copy = copy1.Detach();
+ copy1 = naked_copy; // Test the =(T*) operator.
+ naked_copy->Release();
- copy1.Release();
- EXPECT_FALSE(copy1.IsSameObject(unk2)); // unk2 is valid, copy1 is not
+ copy1.Release();
+ EXPECT_FALSE(copy1.IsSameObject(unk2)); // unk2 is valid, copy1 is not
- // test Interface* constructor
- ScopedComPtr<IMalloc> copy2(static_cast<IMalloc*>(mem_alloc));
- EXPECT_TRUE(copy2.IsSameObject(mem_alloc));
+ // test Interface* constructor
+ ScopedComPtr<IMalloc> copy2(static_cast<IMalloc*>(mem_alloc));
+ EXPECT_TRUE(copy2.IsSameObject(mem_alloc));
- EXPECT_TRUE(SUCCEEDED(unk.QueryFrom(mem_alloc)));
- EXPECT_TRUE(unk != NULL);
- unk.Release();
- EXPECT_TRUE(unk == NULL);
- EXPECT_TRUE(unk.IsSameObject(copy1)); // both are NULL
- }
-
- ::CoUninitialize();
+ EXPECT_TRUE(SUCCEEDED(unk.QueryFrom(mem_alloc)));
+ EXPECT_TRUE(unk != NULL);
+ unk.Release();
+ EXPECT_TRUE(unk == NULL);
+ EXPECT_TRUE(unk.IsSameObject(copy1)); // both are NULL
}
TEST(ScopedComPtrTest, ScopedComPtrVector) {
« no previous file with comments | « no previous file | base/win/shortcut_unittest.cc » ('j') | chrome_frame/test/reliability/reliability_test_suite.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698