implemented google mock config and gave it a quick try (see: add_newValue_writeWasCalled)
This commit is contained in:
parent
ae7a1f70e7
commit
edeae477e1
|
@ -22,6 +22,7 @@
|
|||
#include "CMSWindowsClipboardHTMLConverter.h"
|
||||
#include "CLog.h"
|
||||
#include "CArchMiscWindows.h"
|
||||
#include "CMSWindowsClipboardFacade.h"
|
||||
|
||||
//
|
||||
// CMSWindowsClipboard
|
||||
|
@ -31,7 +32,9 @@ UINT CMSWindowsClipboard::s_ownershipFormat = 0;
|
|||
|
||||
CMSWindowsClipboard::CMSWindowsClipboard(HWND window) :
|
||||
m_window(window),
|
||||
m_time(0)
|
||||
m_time(0),
|
||||
m_facade(new CMSWindowsClipboardFacade()),
|
||||
m_deleteFacade(true)
|
||||
{
|
||||
// add converters, most desired first
|
||||
m_converters.push_back(new CMSWindowsClipboardUTF16Converter);
|
||||
|
@ -47,6 +50,12 @@ CMSWindowsClipboard::CMSWindowsClipboard(HWND window) :
|
|||
CMSWindowsClipboard::~CMSWindowsClipboard()
|
||||
{
|
||||
clearConverters();
|
||||
|
||||
// dependency injection causes confusion over ownership, so we need
|
||||
// logic to decide whether or not we delete the facade. there must
|
||||
// be a more elegant way of doing this.
|
||||
if (m_deleteFacade)
|
||||
delete m_facade;
|
||||
}
|
||||
|
||||
bool
|
||||
|
@ -94,12 +103,7 @@ CMSWindowsClipboard::add(EFormat format, const CString& data)
|
|||
HANDLE win32Data = converter->fromIClipboard(data);
|
||||
if (win32Data != NULL) {
|
||||
UINT win32Format = converter->getWin32Format();
|
||||
if (SetClipboardData(win32Format, win32Data) == NULL) {
|
||||
// free converted data if we couldn't put it on
|
||||
// the clipboard.
|
||||
// nb: couldn't cause this in integ tests.
|
||||
GlobalFree(win32Data);
|
||||
}
|
||||
m_facade->write(win32Data, win32Format);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,16 +19,19 @@
|
|||
#define CMSWINDOWSCLIPBOARD_H
|
||||
|
||||
#include "IClipboard.h"
|
||||
#include "CMSWindowsClipboardFacade.h"
|
||||
#include "stdvector.h"
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#include <windows.h>
|
||||
|
||||
class IMSWindowsClipboardConverter;
|
||||
class IMSWindowsClipboardFacade;
|
||||
|
||||
//! Microsoft windows clipboard implementation
|
||||
class CMSWindowsClipboard : public IClipboard {
|
||||
public:
|
||||
CMSWindowsClipboard(HWND window);
|
||||
CMSWindowsClipboard(HWND window, IMSWindowsClipboardFacade &facade);
|
||||
virtual ~CMSWindowsClipboard();
|
||||
|
||||
//! Empty clipboard without ownership
|
||||
|
@ -58,6 +61,8 @@ public:
|
|||
virtual bool has(EFormat) const;
|
||||
virtual CString get(EFormat) const;
|
||||
|
||||
void setFacade(IMSWindowsClipboardFacade& facade) { m_facade = &facade; m_deleteFacade = false; }
|
||||
|
||||
private:
|
||||
void clearConverters();
|
||||
|
||||
|
@ -74,6 +79,8 @@ private:
|
|||
mutable Time m_time;
|
||||
ConverterList m_converters;
|
||||
static UINT s_ownershipFormat;
|
||||
IMSWindowsClipboardFacade* m_facade;
|
||||
bool m_deleteFacade;
|
||||
};
|
||||
|
||||
//! Clipboard format converter interface
|
||||
|
|
|
@ -0,0 +1,29 @@
|
|||
/*
|
||||
* synergy -- mouse and keyboard sharing utility
|
||||
* Copyright (C) 2002 Chris Schoeneman, Nick Bolton, Sorin Sbarnea
|
||||
*
|
||||
* This package is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* found in the file COPYING that should have accompanied this file.
|
||||
*
|
||||
* This package is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "CMSWindowsClipboard.h"
|
||||
#include "CMSWindowsClipboardFacade.h"
|
||||
|
||||
void CMSWindowsClipboardFacade::write(HANDLE win32Data, UINT win32Format)
|
||||
{
|
||||
if (SetClipboardData(win32Format, win32Data) == NULL) {
|
||||
// free converted data if we couldn't put it on
|
||||
// the clipboard.
|
||||
// nb: couldn't cause this in integ tests.
|
||||
GlobalFree(win32Data);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,30 @@
|
|||
/*
|
||||
* synergy -- mouse and keyboard sharing utility
|
||||
* Copyright (C) 2002 Chris Schoeneman, Nick Bolton, Sorin Sbarnea
|
||||
*
|
||||
* This package is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* found in the file COPYING that should have accompanied this file.
|
||||
*
|
||||
* This package is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef CMSWINDOWSCLIPBOARDFACADE_H
|
||||
#define CMSWINDOWSCLIPBOARDFACADE_H
|
||||
|
||||
#include "IMSWindowsClipboardFacade.h"
|
||||
#include "IClipboard.h"
|
||||
|
||||
class CMSWindowsClipboardFacade : public IMSWindowsClipboardFacade
|
||||
{
|
||||
public:
|
||||
virtual void write(HANDLE win32Data, UINT win32Format);
|
||||
};
|
||||
|
||||
#endif
|
|
@ -29,11 +29,13 @@ if (WIN32)
|
|||
CMSWindowsScreenSaver.h
|
||||
CMSWindowsUtil.h
|
||||
CMSWindowsRelauncher.h
|
||||
IMSWindowsClipboardFacade.h
|
||||
)
|
||||
|
||||
set(src
|
||||
${inc}
|
||||
CMSWindowsClipboard.cpp
|
||||
CMSWindowsClipboardFacade.cpp
|
||||
CMSWindowsClipboardAnyTextConverter.cpp
|
||||
CMSWindowsClipboardBitmapConverter.cpp
|
||||
CMSWindowsClipboardHTMLConverter.cpp
|
||||
|
|
|
@ -0,0 +1,34 @@
|
|||
/*
|
||||
* synergy -- mouse and keyboard sharing utility
|
||||
* Copyright (C) 2002 Chris Schoeneman, Nick Bolton, Sorin Sbarnea
|
||||
*
|
||||
* This package is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* found in the file COPYING that should have accompanied this file.
|
||||
*
|
||||
* This package is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef IMWINDOWSCLIPBOARDFACADE
|
||||
#define IMWINDOWSCLIPBOARDFACADE
|
||||
|
||||
#include "IInterface.h"
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#include <windows.h>
|
||||
|
||||
class IMSWindowsClipboardConverter;
|
||||
|
||||
class IMSWindowsClipboardFacade : public IInterface
|
||||
{
|
||||
public:
|
||||
virtual void write(HANDLE win32Data, UINT win32Format) = 0;
|
||||
virtual ~IMSWindowsClipboardFacade() { }
|
||||
};
|
||||
|
||||
#endif
|
|
@ -14,10 +14,13 @@
|
|||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
include_directories(
|
||||
../../tools/gtest
|
||||
../../tools/gtest/include)
|
||||
|
||||
add_library(gtest STATIC ../../tools/gtest/src/gtest-all.cc)
|
||||
../../tools/gtest-1.6.0
|
||||
../../tools/gtest-1.6.0/include
|
||||
../../tools/gmock-1.6.0
|
||||
../../tools/gmock-1.6.0/include)
|
||||
|
||||
add_library(gtest STATIC ../../tools/gtest-1.6.0/src/gtest-all.cc)
|
||||
add_library(gmock STATIC ../../tools/gmock-1.6.0/src/gmock-all.cc)
|
||||
|
||||
add_subdirectory(integtests)
|
||||
add_subdirectory(unittests)
|
||||
|
|
|
@ -50,7 +50,8 @@ set(inc
|
|||
../../lib/net
|
||||
../../lib/platform
|
||||
../../lib/synergy
|
||||
../../../tools/gtest/include
|
||||
../../../tools/gtest-1.6.0/include
|
||||
../../../tools/gmock-1.6.0/include
|
||||
)
|
||||
|
||||
if (UNIX)
|
||||
|
@ -62,4 +63,4 @@ endif()
|
|||
include_directories(${inc})
|
||||
add_executable(integtests ${src})
|
||||
target_link_libraries(integtests
|
||||
arch base client common io mt net platform server synergy gtest ${libs})
|
||||
arch base client common io mt net platform server synergy gtest gmock ${libs})
|
||||
|
|
|
@ -16,8 +16,9 @@
|
|||
*/
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
#include <gmock/gmock.h>
|
||||
#include "CMSWindowsClipboard.h"
|
||||
|
||||
#include "IMSWindowsClipboardFacade.h"
|
||||
|
||||
class CMSWindowsClipboardTests : public ::testing::Test
|
||||
{
|
||||
|
@ -41,6 +42,12 @@ private:
|
|||
}
|
||||
};
|
||||
|
||||
class MockFacade : public IMSWindowsClipboardFacade
|
||||
{
|
||||
public:
|
||||
MOCK_METHOD2(write, void(HANDLE, UINT));
|
||||
};
|
||||
|
||||
TEST_F(CMSWindowsClipboardTests, emptyUnowned_openCalled_returnsTrue)
|
||||
{
|
||||
CMSWindowsClipboard clipboard(NULL);
|
||||
|
@ -84,6 +91,18 @@ TEST_F(CMSWindowsClipboardTests, add_newValue_valueWasStored)
|
|||
EXPECT_EQ("synergy rocks!", actual);
|
||||
}
|
||||
|
||||
TEST_F(CMSWindowsClipboardTests, add_newValue_writeWasCalled)
|
||||
{
|
||||
MockFacade facade;
|
||||
EXPECT_CALL(facade, write(testing::_, testing::_));
|
||||
|
||||
CMSWindowsClipboard clipboard(NULL);
|
||||
clipboard.setFacade(facade);
|
||||
clipboard.open(0);
|
||||
|
||||
clipboard.add(IClipboard::kText, "synergy rocks!");
|
||||
}
|
||||
|
||||
TEST_F(CMSWindowsClipboardTests, add_replaceValue_valueWasReplaced)
|
||||
{
|
||||
CMSWindowsClipboard clipboard(NULL);
|
||||
|
|
|
@ -14,7 +14,7 @@
|
|||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
set(src
|
||||
../../../tools/gtest/src/gtest_main.cc
|
||||
../../../tools/gtest-1.6.0/src/gtest_main.cc
|
||||
synergy/CClipboardTests.cpp
|
||||
)
|
||||
|
||||
|
@ -28,7 +28,8 @@ set(inc
|
|||
../../lib/net
|
||||
../../lib/platform
|
||||
../../lib/synergy
|
||||
../../../tools/gtest/include
|
||||
../../../tools/gtest-1.6.0/include
|
||||
../../../tools/gmock-1.6.0/include
|
||||
)
|
||||
|
||||
if (UNIX)
|
||||
|
@ -40,4 +41,4 @@ endif()
|
|||
include_directories(${inc})
|
||||
add_executable(unittests ${src})
|
||||
target_link_libraries(unittests
|
||||
arch base client common io mt net platform server synergy gtest ${libs})
|
||||
arch base client common io mt net platform server synergy gtest gmock ${libs})
|
||||
|
|
Loading…
Reference in New Issue