Skip to content

Commit

Permalink
Merge pull request #1800 from k-kagari/feature/use-mock-in-test-cclip…
Browse files Browse the repository at this point in the history
…board

CClipboard のテストにモックを導入する
  • Loading branch information
kengoide committed Feb 14, 2022
2 parents bdae441 + d2a0f72 commit e013bcd
Show file tree
Hide file tree
Showing 7 changed files with 321 additions and 18 deletions.
42 changes: 29 additions & 13 deletions sakura_core/_os/CClipboard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ CClipboard::~CClipboard()

void CClipboard::Empty()
{
::EmptyClipboard();
EmptyClipboard();
}

void CClipboard::Close()
Expand Down Expand Up @@ -112,7 +112,7 @@ bool CClipboard::SetText(
::GlobalUnlock( hgClipText );

//クリップボードに設定
::SetClipboardData( CF_UNICODETEXT, hgClipText );
SetClipboardData( CF_UNICODETEXT, hgClipText );
bUnicodeText = false;
}
// 1回しか通らない. breakでここまで飛ぶ
Expand Down Expand Up @@ -142,7 +142,7 @@ bool CClipboard::SetText(
::GlobalUnlock( hgClipSakura );

//クリップボードに設定
::SetClipboardData( uFormatSakuraClip, hgClipSakura );
SetClipboardData( uFormatSakuraClip, hgClipSakura );
bSakuraText = false;
}
// 1回しか通らない. breakでここまで飛ぶ
Expand All @@ -160,7 +160,7 @@ bool CClipboard::SetText(
BYTE* pClip = GlobalLockBYTE( hgClipMSDEVColumn );
pClip[0] = 0;
::GlobalUnlock( hgClipMSDEVColumn );
::SetClipboardData( uFormat, hgClipMSDEVColumn );
SetClipboardData( uFormat, hgClipMSDEVColumn );
}
}
}
Expand All @@ -178,7 +178,7 @@ bool CClipboard::SetText(
BYTE* pClip = (BYTE*)::GlobalLock( hgClipMSDEVLine );
pClip[0] = 0x01;
::GlobalUnlock( hgClipMSDEVLine );
::SetClipboardData( uFormat, hgClipMSDEVLine );
SetClipboardData( uFormat, hgClipMSDEVLine );
}
}
}
Expand All @@ -194,7 +194,7 @@ bool CClipboard::SetText(
BYTE* pClip = (BYTE*)::GlobalLock( hgClipMSDEVLine2 );
pClip[0] = 0x01; // ※ ClipSpy で調べるとデータはこれとは違うが内容には無関係に動くっぽい
::GlobalUnlock( hgClipMSDEVLine2 );
::SetClipboardData( uFormat, hgClipMSDEVLine2 );
SetClipboardData( uFormat, hgClipMSDEVLine2 );
}
}
}
Expand Down Expand Up @@ -250,7 +250,7 @@ bool CClipboard::SetHtmlText(const CNativeW& cmemBUf)

//クリップボードに設定
UINT uFormat = ::RegisterClipboardFormat( L"HTML Format" );
::SetClipboardData( uFormat, hgClipText );
SetClipboardData( uFormat, hgClipText );
return true;
}

Expand Down Expand Up @@ -299,8 +299,8 @@ bool CClipboard::GetText(CNativeW* cmemBuf, bool* pbColumnSelect, bool* pbLineSe
//サクラ形式のデータがあれば取得
CLIPFORMAT uFormatSakuraClip = CClipboard::GetSakuraFormat();
if( (uGetFormat == -1 || uGetFormat == uFormatSakuraClip)
&& ::IsClipboardFormatAvailable( uFormatSakuraClip ) ){
HGLOBAL hSakura = ::GetClipboardData( uFormatSakuraClip );
&& IsClipboardFormatAvailable( uFormatSakuraClip ) ){
HGLOBAL hSakura = GetClipboardData( uFormatSakuraClip );
if (hSakura != NULL) {
BYTE* pData = (BYTE*)::GlobalLock(hSakura);
size_t nLength = *((int*)pData);
Expand All @@ -315,7 +315,7 @@ bool CClipboard::GetText(CNativeW* cmemBuf, bool* pbColumnSelect, bool* pbLineSe
// From Here 2005/05/29 novice UNICODE TEXT 対応処理を追加
HGLOBAL hUnicode = NULL;
if( uGetFormat == -1 || uGetFormat == CF_UNICODETEXT ){
hUnicode = ::GetClipboardData( CF_UNICODETEXT );
hUnicode = GetClipboardData( CF_UNICODETEXT );
}
if( hUnicode != NULL ){
//DWORD nLen = GlobalSize(hUnicode);
Expand All @@ -329,7 +329,7 @@ bool CClipboard::GetText(CNativeW* cmemBuf, bool* pbColumnSelect, bool* pbLineSe
//OEMTEXT形式のデータがあれば取得
HGLOBAL hText = NULL;
if( uGetFormat == -1 || uGetFormat == CF_OEMTEXT ){
hText = ::GetClipboardData( CF_OEMTEXT );
hText = GetClipboardData( CF_OEMTEXT );
}
if( hText != NULL ){
char* szData = GlobalLockChar(hText);
Expand All @@ -348,8 +348,8 @@ bool CClipboard::GetText(CNativeW* cmemBuf, bool* pbColumnSelect, bool* pbLineSe
/* 2008.09.10 bosagami パス貼り付け対応 */
//HDROP形式のデータがあれば取得
if( (uGetFormat == -1 || uGetFormat == CF_HDROP)
&& ::IsClipboardFormatAvailable(CF_HDROP) ){
HDROP hDrop = (HDROP)::GetClipboardData(CF_HDROP);
&& IsClipboardFormatAvailable(CF_HDROP) ){
HDROP hDrop = (HDROP)GetClipboardData(CF_HDROP);
if(hDrop != NULL){
WCHAR sTmpPath[_MAX_PATH + 1] = {0};
const int nMaxCnt = DragQueryFile(hDrop, 0xFFFFFFFF, NULL, 0);
Expand Down Expand Up @@ -673,3 +673,19 @@ int CClipboard::GetDataType()
if(::IsClipboardFormatAvailable(CF_HDROP))return CF_HDROP;
return -1;
}

HANDLE CClipboard::SetClipboardData(UINT uFormat, HANDLE hMem) const {
return ::SetClipboardData(uFormat, hMem);
}

HANDLE CClipboard::GetClipboardData(UINT uFormat) const {
return ::GetClipboardData(uFormat);
}

BOOL CClipboard::EmptyClipboard() const {
return ::EmptyClipboard();
}

BOOL CClipboard::IsClipboardFormatAvailable(UINT format) const {
return ::IsClipboardFormatAvailable(format);
}
11 changes: 11 additions & 0 deletions sakura_core/_os/CClipboard.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,5 +66,16 @@ class CClipboard{
static bool HasValidData(); //!< クリップボード内に、サクラエディタで扱えるデータがあればtrue
static CLIPFORMAT GetSakuraFormat(); //!< サクラエディタ独自のクリップボードデータ形式
static int GetDataType(); //!< クリップボードデータ形式(CF_UNICODETEXT等)の取得

protected:
// 単体テスト用コンストラクタ
explicit CClipboard(bool openStatus) : m_bOpenResult(openStatus) {}

// 同名の Windows API に引数を転送する仮想メンバ関数。
// 単体テスト内でオーバーライドすることで副作用のないテストを実施するのが目的。
virtual HANDLE SetClipboardData(UINT uFormat, HANDLE hMem) const;
virtual HANDLE GetClipboardData(UINT uFormat) const;
virtual BOOL EmptyClipboard() const;
virtual BOOL IsClipboardFormatAvailable(UINT format) const;
};
#endif /* SAKURA_CCLIPBOARD_4E783022_214C_4E51_A2E0_54EC343500F6_H_ */
1 change: 1 addition & 0 deletions sakura_core/cmd/CViewCommander_Clipboard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include "uiparts/CWaitCursor.h"
#include "util/os.h"
#include "apiwrap/CommonControl.h"
#include "_os/CClipboard.h"

/** 切り取り(選択範囲をクリップボードにコピーして削除)
Expand Down
6 changes: 6 additions & 0 deletions sakura_core/doc/CDocEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
#include "CEol.h"
#include "window/CEditWnd.h"
#include "debug/CRunningTimer.h"
#include "_os/CClipboard.h"

CDocEditor::CDocEditor(CEditDoc* pcDoc)
: m_pcDocRef(pcDoc)
Expand Down Expand Up @@ -166,6 +167,11 @@ void CDocEditor::SetImeMode( int mode )
}
// To Here Nov. 20, 2000 genta

bool CDocEditor::IsEnablePaste() const
{
return CClipboard::HasValidData();
}

/*!
末尾に行を追加
Expand Down
6 changes: 1 addition & 5 deletions sakura_core/doc/CDocEditor.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
#pragma once

#include "doc/CDocListener.h"
#include "_os/CClipboard.h"
#include "COpeBuf.h"

class CEditDoc;
Expand Down Expand Up @@ -84,10 +83,7 @@ class CDocEditor : public CDocListenerEx{
}

//! クリップボードから貼り付け可能か?
bool IsEnablePaste( void ) const
{
return CClipboard::HasValidData();
}
bool IsEnablePaste( void ) const;

public:
CEditDoc* m_pcDocRef;
Expand Down
1 change: 1 addition & 0 deletions sakura_core/macro/CMacro.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
#include "CSelectLang.h"
#include "config/app_constants.h"
#include "String_define.h"
#include "_os/CClipboard.h"

CMacro::CMacro( EFunctionCode nFuncID )
{
Expand Down

0 comments on commit e013bcd

Please sign in to comment.