-
Notifications
You must be signed in to change notification settings - Fork 162
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
CClipboard のテストにモックを導入する #1800
CClipboard のテストにモックを導入する #1800
Changes from all commits
733f16e
e7a0b5c
a5a85a8
eca61cc
d2a0f72
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -56,7 +56,7 @@ CClipboard::~CClipboard() | |
|
||
void CClipboard::Empty() | ||
{ | ||
::EmptyClipboard(); | ||
EmptyClipboard(); | ||
} | ||
|
||
void CClipboard::Close() | ||
|
@@ -112,7 +112,7 @@ bool CClipboard::SetText( | |
::GlobalUnlock( hgClipText ); | ||
|
||
//クリップボードに設定 | ||
::SetClipboardData( CF_UNICODETEXT, hgClipText ); | ||
SetClipboardData( CF_UNICODETEXT, hgClipText ); | ||
bUnicodeText = false; | ||
} | ||
// 1回しか通らない. breakでここまで飛ぶ | ||
|
@@ -142,7 +142,7 @@ bool CClipboard::SetText( | |
::GlobalUnlock( hgClipSakura ); | ||
|
||
//クリップボードに設定 | ||
::SetClipboardData( uFormatSakuraClip, hgClipSakura ); | ||
SetClipboardData( uFormatSakuraClip, hgClipSakura ); | ||
bSakuraText = false; | ||
} | ||
// 1回しか通らない. breakでここまで飛ぶ | ||
|
@@ -160,7 +160,7 @@ bool CClipboard::SetText( | |
BYTE* pClip = GlobalLockBYTE( hgClipMSDEVColumn ); | ||
pClip[0] = 0; | ||
::GlobalUnlock( hgClipMSDEVColumn ); | ||
::SetClipboardData( uFormat, hgClipMSDEVColumn ); | ||
SetClipboardData( uFormat, hgClipMSDEVColumn ); | ||
} | ||
} | ||
} | ||
|
@@ -178,7 +178,7 @@ bool CClipboard::SetText( | |
BYTE* pClip = (BYTE*)::GlobalLock( hgClipMSDEVLine ); | ||
pClip[0] = 0x01; | ||
::GlobalUnlock( hgClipMSDEVLine ); | ||
::SetClipboardData( uFormat, hgClipMSDEVLine ); | ||
SetClipboardData( uFormat, hgClipMSDEVLine ); | ||
} | ||
} | ||
} | ||
|
@@ -194,7 +194,7 @@ bool CClipboard::SetText( | |
BYTE* pClip = (BYTE*)::GlobalLock( hgClipMSDEVLine2 ); | ||
pClip[0] = 0x01; // ※ ClipSpy で調べるとデータはこれとは違うが内容には無関係に動くっぽい | ||
::GlobalUnlock( hgClipMSDEVLine2 ); | ||
::SetClipboardData( uFormat, hgClipMSDEVLine2 ); | ||
SetClipboardData( uFormat, hgClipMSDEVLine2 ); | ||
} | ||
} | ||
} | ||
|
@@ -250,7 +250,7 @@ bool CClipboard::SetHtmlText(const CNativeW& cmemBUf) | |
|
||
//クリップボードに設定 | ||
UINT uFormat = ::RegisterClipboardFormat( L"HTML Format" ); | ||
::SetClipboardData( uFormat, hgClipText ); | ||
SetClipboardData( uFormat, hgClipText ); | ||
return true; | ||
} | ||
|
||
|
@@ -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); | ||
|
@@ -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); | ||
|
@@ -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); | ||
|
@@ -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); | ||
|
@@ -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); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. このAPI関数ですが、クラスメンバを利用しないのでconst関数とすべきだと思います。 他のAPI関数も同様です。 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. const にしました。 |
||
} | ||
|
||
HANDLE CClipboard::GetClipboardData(UINT uFormat) const { | ||
return ::GetClipboardData(uFormat); | ||
} | ||
|
||
BOOL CClipboard::EmptyClipboard() const { | ||
return ::EmptyClipboard(); | ||
} | ||
|
||
BOOL CClipboard::IsClipboardFormatAvailable(UINT format) const { | ||
return ::IsClipboardFormatAvailable(format); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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) {} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ここにexplicitを付けるなら、元々定義されているコンストラクタにも付けるべきと思いました。 コメントで書きましたが元のコンストラクタがおかしいので、ここに追加したコンストラクタは将来的に削除されることになると思っています。 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 既存のコードの改善を始める前にテストを整備したいので元のコンストラクタには手を付けていません。 失敗の可能性があるコンストラクタは static なファクトリー関数に置き換えるのが良いと考えています。クリップボードのオープンに失敗したら即座に呼び出し元に通知するべきです。状態を持つ必要がなくなるのでクラス内の条件分岐が減らせます。 このあたりの設計については各論あると思いますのでまたの機会に詳しく検討させてください。 |
||
|
||
// 同名の 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_ */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ぬおっ!
やり方色々あるっす。
たとえばこんな感じです。
CClipboardApi::getInstance()->EmptyClipboard();