From 5d67aee68bd072db2bbeef3e1f8508425d96af72 Mon Sep 17 00:00:00 2001 From: "mad@google.com" Date: Mon, 8 Nov 2010 18:27:23 +0000 Subject: Fixed failing unittests. Some tests were explicitly setting the last error that an expected mock method would have set in the real world, but some code in the mean time can reset it to zero, so we now set the error code as part of the mocked expectation using testing::Invoke. BUG=None Test=Make sure the unit tests always succeed. Review URL: http://codereview.chromium.org/4646002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@65400 0039d316-1c4b-4281-b951-d872f2087c98 --- ceee/ie/plugin/bho/executor_unittest.cc | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) (limited to 'ceee') diff --git a/ceee/ie/plugin/bho/executor_unittest.cc b/ceee/ie/plugin/bho/executor_unittest.cc index e260fd3..d68f2d0 100644 --- a/ceee/ie/plugin/bho/executor_unittest.cc +++ b/ceee/ie/plugin/bho/executor_unittest.cc @@ -46,6 +46,7 @@ using testing::NotNull; using testing::Return; using testing::SetArgumentPointee; using testing::StrictMock; +using testing::WithoutArgs; const int kGoodWindowId = 42; const HWND kGoodWindow = reinterpret_cast(kGoodWindowId); @@ -127,6 +128,11 @@ class TestingExecutorCreator : public CeeeExecutorCreator { using CeeeExecutorCreator::GetMsgProc; }; +template +void SetFakeLastError() { + ::SetLastError(error_code); +} + TEST(ExecutorCreator, CreateExecutor) { testing::LogDisabler no_dchecks; @@ -143,8 +149,8 @@ TEST(ExecutorCreator, CreateExecutor) { EXPECT_CALL(mock_hooking, SetWindowsHookEx(WH_GETMESSAGE, _, _, 42L)). WillRepeatedly(Return(reinterpret_cast(1))); EXPECT_CALL(mock_hooking, PostThreadMessage(42L, _, 0, 0)). - WillOnce(Return(FALSE)); - ::SetLastError(ERROR_INVALID_ACCESS); + WillOnce(DoAll(WithoutArgs(Invoke( + SetFakeLastError)), Return(FALSE))); EXPECT_HRESULT_FAILED(executor_creator.CreateWindowExecutor(42L, 0L)); ::SetLastError(ERROR_SUCCESS); @@ -462,8 +468,8 @@ TEST_F(ExecutorTests, GetWindow) { EXPECT_CALL(mock_window_utils_, GetTopLevelParent(kGoodWindow)). WillRepeatedly(Return(kGoodWindow)); EXPECT_CALL(user32_, GetWindowRect(kGoodWindow, NotNull())). - WillOnce(Return(FALSE)); - ::SetLastError(ERROR_INVALID_ACCESS); + WillOnce(DoAll(WithoutArgs(Invoke( + SetFakeLastError)), Return(FALSE))); common_api::WindowInfo window_info; EXPECT_HRESULT_FAILED(executor_->GetWindow(FALSE, &window_info)); EXPECT_EQ(NULL, window_info.tab_list); @@ -938,18 +944,20 @@ TEST_F(ExecutorTests, GetCookieValue) { // Failure to get cookie. EXPECT_CALL(mock_wininet, InternetGetCookieExW(_, _, IsNull(), _, _, _)) - .WillOnce(Return(FALSE)); - ::SetLastError(ERROR_INVALID_PARAMETER); + .WillOnce(DoAll(WithoutArgs(Invoke( + SetFakeLastError)), Return(FALSE))); CComBSTR value; EXPECT_HRESULT_FAILED(executor_->CallGetCookieValue(url, name, &value)); EXPECT_EQ((BSTR)NULL, value); + ::SetLastError(ERROR_SUCCESS); // Nonexistent cookie. EXPECT_CALL(mock_wininet, InternetGetCookieExW(_, _, IsNull(), _, _, _)) - .WillOnce(Return(FALSE)); - ::SetLastError(ERROR_NO_MORE_ITEMS); + .WillOnce(DoAll(WithoutArgs(Invoke( + SetFakeLastError)), Return(FALSE))); EXPECT_EQ(S_FALSE, executor_->CallGetCookieValue(url, name, &value)); EXPECT_EQ((BSTR)NULL, value); + ::SetLastError(ERROR_SUCCESS); // Malformed cookie. EXPECT_CALL(mock_wininet, InternetGetCookieExW(_, _, IsNull(), _, _, _)) -- cgit v1.1