diff options
author | initial.commit@chromium.org <initial.commit@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-11-02 02:14:31 +0000 |
---|---|---|
committer | initial.commit@chromium.org <initial.commit@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-11-02 02:14:31 +0000 |
commit | 5a7bdf208c28c210b39cff63d1cf91302b02821b (patch) | |
tree | 5ff484561562f78b29d2670168a9e3b40b48dcab /ceee/common/com_utils_unittest.cc | |
parent | 26a54a5e0f4603c8fda2fe51789d331125993c9a (diff) | |
download | chromium_src-5a7bdf208c28c210b39cff63d1cf91302b02821b.zip chromium_src-5a7bdf208c28c210b39cff63d1cf91302b02821b.tar.gz chromium_src-5a7bdf208c28c210b39cff63d1cf91302b02821b.tar.bz2 |
Checking in the initial version of CEEE (Chrome Extensions Execution
Environment), an optional feature of Chrome Frame that acts as an
adapter layer for a subset of the Chrome Extension APIs. This enables
extensions that stick to the supported subset of APIs to work in the
context of Chrome Frame with minimal or sometimes no changes.
See http://www.chromium.org/developers/design-documents/ceee for an
overview of the design of CEEE.
TEST=unit tests (run ceee/smoke_tests.bat as an administrator on Windows)
BUG=none
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@64712 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ceee/common/com_utils_unittest.cc')
-rw-r--r-- | ceee/common/com_utils_unittest.cc | 143 |
1 files changed, 143 insertions, 0 deletions
diff --git a/ceee/common/com_utils_unittest.cc b/ceee/common/com_utils_unittest.cc new file mode 100644 index 0000000..ea27f84 --- /dev/null +++ b/ceee/common/com_utils_unittest.cc @@ -0,0 +1,143 @@ +// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. +// +// Unit tests for COM utils. + +#include "ceee/common/com_utils.h" + +#include <atlcomcli.h> + +#include "ceee/testing/utils/mock_win32.h" +#include "ceee/testing/utils/mock_static.h" +#include "ceee/testing/utils/test_utils.h" +#include "testing/gmock/include/gmock/gmock.h" +#include "testing/gtest/include/gtest/gtest.h" + +namespace com { + +HRESULT UpdateRegistryFromResourceImpl(int reg_id, BOOL should_register, + _ATL_REGMAP_ENTRY* entries); + +} // namespace com; + +namespace { + +using testing::_; +using testing::DoAll; +using testing::CopyStringToArgument; +using testing::Field; +using testing::Pointee; +using testing::Return; +using testing::StrEq; + +TEST(ComUtils, AlwaysError) { + EXPECT_EQ(com::AlwaysError(S_OK, E_INVALIDARG), E_INVALIDARG); + EXPECT_EQ(com::AlwaysError(E_FAIL, E_INVALIDARG), E_FAIL); + + EXPECT_EQ(com::AlwaysError(S_OK), E_FAIL); + EXPECT_EQ(com::AlwaysError(E_FAIL), E_FAIL); + + EXPECT_EQ(com::AlwaysErrorFromWin32(NO_ERROR, E_INVALIDARG), E_INVALIDARG); + EXPECT_EQ(com::AlwaysErrorFromWin32(NO_ERROR), E_FAIL); + + EXPECT_EQ(com::AlwaysErrorFromWin32(ERROR_ACCESS_DENIED, E_INVALIDARG), + HRESULT_FROM_WIN32(ERROR_ACCESS_DENIED)); + EXPECT_EQ(com::AlwaysErrorFromWin32(ERROR_ACCESS_DENIED), + HRESULT_FROM_WIN32(ERROR_ACCESS_DENIED)); + + DWORD last_error = ::GetLastError(); + + ::SetLastError(NO_ERROR); + EXPECT_EQ(com::AlwaysErrorFromLastError(E_INVALIDARG), E_INVALIDARG); + EXPECT_EQ(com::AlwaysErrorFromLastError(), E_FAIL); + + ::SetLastError(ERROR_ACCESS_DENIED); + EXPECT_EQ(com::AlwaysErrorFromLastError(E_INVALIDARG), + HRESULT_FROM_WIN32(ERROR_ACCESS_DENIED)); + EXPECT_EQ(com::AlwaysErrorFromLastError(), + HRESULT_FROM_WIN32(ERROR_ACCESS_DENIED)); + + ::SetLastError(last_error); +} + +TEST(ComUtils, ToString) { + CComBSTR filled(L"hello"); + EXPECT_STREQ(com::ToString(filled), L"hello"); + + CComBSTR empty; + EXPECT_STREQ(com::ToString(empty), L""); +} + +TEST(ComUtils, HrLog) { + { + std::ostringstream stream; + stream << com::LogHr(S_OK); + std::string str = stream.str(); + EXPECT_NE(str.find("0x0,"), std::string::npos); + EXPECT_NE(str.find("msg="), std::string::npos); + } + + { + std::ostringstream stream; + stream << com::LogHr(E_FAIL); + std::string str = stream.str(); + EXPECT_NE(str.find("0x80004005,"), std::string::npos); + EXPECT_NE(str.find("msg=Unspecified error"), std::string::npos); + } +} + +TEST(ComUtils, WeLog) { + { + std::ostringstream stream; + stream << com::LogWe(ERROR_SUCCESS); + std::string str = stream.str(); + EXPECT_NE(str.find("[we=0,"), std::string::npos); + EXPECT_NE(str.find("msg=The operation completed successfully"), + std::string::npos); + } + + { + std::ostringstream stream; + stream << com::LogWe(ERROR_INVALID_FUNCTION); + std::string str = stream.str(); + EXPECT_NE(str.find("[we=1,"), std::string::npos); + EXPECT_NE(str.find("msg=Incorrect function"), std::string::npos); + } +} + +HRESULT UpdateRegistryFromResourceImpl(int reg_id, BOOL should_register, + _ATL_REGMAP_ENTRY* entries) { + return _pAtlModule->UpdateRegistryFromResource( + reg_id, should_register, entries); +} + +// Mock out UpdateRegistryFromResourceImpl. +MOCK_STATIC_CLASS_BEGIN(MockModuleRegistrationWithoutAppid) + MOCK_STATIC_INIT_BEGIN(MockModuleRegistrationWithoutAppid) + MOCK_STATIC_INIT2(com::UpdateRegistryFromResourceImpl, + UpdateRegistryFromResourceImpl); + MOCK_STATIC_INIT_END() + + MOCK_STATIC3(HRESULT, , UpdateRegistryFromResourceImpl, + int, BOOL, _ATL_REGMAP_ENTRY*); +MOCK_STATIC_CLASS_END(MockModuleRegistrationWithoutAppid) + +MATCHER(ValidateRegmapComponents, "Checks regmap for correct values") { + return 0 == lstrcmpW(arg[0].szData, L"c:\\foo\\blat") && + 0 == lstrcmpW(arg[1].szData, L"bingo.exe"); +} + +TEST_DEBUG_ONLY(ComUtils, ModuleRegistrationWithoutAppid) { + MockModuleRegistrationWithoutAppid mock; + EXPECT_CALL(mock, UpdateRegistryFromResourceImpl( + 42, TRUE, ValidateRegmapComponents())).WillRepeatedly(Return(S_OK)); + + testing::MockKernel32 kernel32; + EXPECT_CALL(kernel32, GetModuleFileName(_, _, _)).WillRepeatedly(DoAll( + CopyStringToArgument<1>(L"c:\\foo\\blat\\bingo.exe"), Return(1))); + + EXPECT_EQ(S_OK, com::ModuleRegistrationWithoutAppid(42, TRUE)); +} + +} // namespace |