finished CMSWindowsClipboardTests
This commit is contained in:
parent
061e1e109b
commit
7cd8980f7f
|
@ -56,6 +56,8 @@ CMSWindowsClipboard::emptyUnowned()
|
||||||
|
|
||||||
// empty the clipboard (and take ownership)
|
// empty the clipboard (and take ownership)
|
||||||
if (!EmptyClipboard()) {
|
if (!EmptyClipboard()) {
|
||||||
|
// unable to cause this in integ tests, but this error has never
|
||||||
|
// actually been reported by users.
|
||||||
LOG((CLOG_DEBUG "failed to grab clipboard"));
|
LOG((CLOG_DEBUG "failed to grab clipboard"));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -94,7 +96,8 @@ CMSWindowsClipboard::add(EFormat format, const CString& data)
|
||||||
UINT win32Format = converter->getWin32Format();
|
UINT win32Format = converter->getWin32Format();
|
||||||
if (SetClipboardData(win32Format, win32Data) == NULL) {
|
if (SetClipboardData(win32Format, win32Data) == NULL) {
|
||||||
// free converted data if we couldn't put it on
|
// free converted data if we couldn't put it on
|
||||||
// the clipboard
|
// the clipboard.
|
||||||
|
// nb: couldn't cause this in integ tests.
|
||||||
GlobalFree(win32Data);
|
GlobalFree(win32Data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -108,7 +111,11 @@ CMSWindowsClipboard::open(Time time) const
|
||||||
LOG((CLOG_DEBUG "open clipboard"));
|
LOG((CLOG_DEBUG "open clipboard"));
|
||||||
|
|
||||||
if (!OpenClipboard(m_window)) {
|
if (!OpenClipboard(m_window)) {
|
||||||
LOG((CLOG_WARN "failed to open clipboard"));
|
// unable to cause this in integ tests; but this can happen!
|
||||||
|
// * http://synergy-foss.org/pm/issues/86
|
||||||
|
// * http://synergy-foss.org/pm/issues/1256
|
||||||
|
// logging improved to see if we can catch more info next time.
|
||||||
|
LOG((CLOG_WARN "failed to open clipboard: %d", GetLastError()));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -172,6 +179,9 @@ CMSWindowsClipboard::get(EFormat format) const
|
||||||
// get a handle to the clipboard data
|
// get a handle to the clipboard data
|
||||||
HANDLE win32Data = GetClipboardData(converter->getWin32Format());
|
HANDLE win32Data = GetClipboardData(converter->getWin32Format());
|
||||||
if (win32Data == NULL) {
|
if (win32Data == NULL) {
|
||||||
|
// nb: can't cause this using integ tests; this is only caused when
|
||||||
|
// the selected converter returns an invalid format -- which you
|
||||||
|
// cannot cause using public functions.
|
||||||
return CString();
|
return CString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -27,3 +27,155 @@ TEST(CMSWindowsClipboardTests, emptyUnowned_openCalled_returnsTrue)
|
||||||
|
|
||||||
EXPECT_EQ(true, actual);
|
EXPECT_EQ(true, actual);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST(CMSWindowsClipboardTests, empty_openCalled_returnsTrue)
|
||||||
|
{
|
||||||
|
CMSWindowsClipboard clipboard(NULL);
|
||||||
|
clipboard.open(0);
|
||||||
|
|
||||||
|
bool actual = clipboard.empty();
|
||||||
|
|
||||||
|
EXPECT_EQ(true, actual);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(CMSWindowsClipboardTests, empty_singleFormat_hasReturnsFalse)
|
||||||
|
{
|
||||||
|
CMSWindowsClipboard clipboard(NULL);
|
||||||
|
clipboard.open(0);
|
||||||
|
clipboard.add(CMSWindowsClipboard::kText, "synergy rocks!");
|
||||||
|
|
||||||
|
clipboard.empty();
|
||||||
|
|
||||||
|
bool actual = clipboard.has(CMSWindowsClipboard::kText);
|
||||||
|
EXPECT_EQ(false, actual);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(CMSWindowsClipboardTests, add_newValue_valueWasStored)
|
||||||
|
{
|
||||||
|
CMSWindowsClipboard clipboard(NULL);
|
||||||
|
clipboard.open(0);
|
||||||
|
|
||||||
|
clipboard.add(IClipboard::kText, "synergy rocks!");
|
||||||
|
|
||||||
|
CString actual = clipboard.get(IClipboard::kText);
|
||||||
|
EXPECT_EQ("synergy rocks!", actual);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(CMSWindowsClipboardTests, add_replaceValue_valueWasReplaced)
|
||||||
|
{
|
||||||
|
CMSWindowsClipboard clipboard(NULL);
|
||||||
|
clipboard.open(0);
|
||||||
|
|
||||||
|
clipboard.add(IClipboard::kText, "synergy rocks!");
|
||||||
|
clipboard.add(IClipboard::kText, "maxivista sucks"); // haha, just kidding.
|
||||||
|
|
||||||
|
CString actual = clipboard.get(IClipboard::kText);
|
||||||
|
EXPECT_EQ("maxivista sucks", actual);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(CMSWindowsClipboardTests, open_timeIsZero_returnsTrue)
|
||||||
|
{
|
||||||
|
CMSWindowsClipboard clipboard(NULL);
|
||||||
|
|
||||||
|
bool actual = clipboard.open(0);
|
||||||
|
|
||||||
|
EXPECT_EQ(true, actual);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(CMSWindowsClipboardTests, open_timeIsOne_returnsTrue)
|
||||||
|
{
|
||||||
|
CMSWindowsClipboard clipboard(NULL);
|
||||||
|
|
||||||
|
bool actual = clipboard.open(1);
|
||||||
|
|
||||||
|
EXPECT_EQ(true, actual);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(CMSWindowsClipboardTests, close_isOpen_noErrors)
|
||||||
|
{
|
||||||
|
CMSWindowsClipboard clipboard(NULL);
|
||||||
|
clipboard.open(0);
|
||||||
|
|
||||||
|
clipboard.close();
|
||||||
|
|
||||||
|
// can't assert anything
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(CMSWindowsClipboardTests, getTime_openWithNoEmpty_returnsOne)
|
||||||
|
{
|
||||||
|
CMSWindowsClipboard clipboard(NULL);
|
||||||
|
clipboard.open(1);
|
||||||
|
|
||||||
|
CMSWindowsClipboard::Time actual = clipboard.getTime();
|
||||||
|
|
||||||
|
// this behavior is different to that of CClipboard which only
|
||||||
|
// returns the value passed into open(t) after empty() is called.
|
||||||
|
EXPECT_EQ(1, actual);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(CMSWindowsClipboardTests, getTime_openAndEmpty_returnsOne)
|
||||||
|
{
|
||||||
|
CMSWindowsClipboard clipboard(NULL);
|
||||||
|
clipboard.open(1);
|
||||||
|
clipboard.empty();
|
||||||
|
|
||||||
|
CMSWindowsClipboard::Time actual = clipboard.getTime();
|
||||||
|
|
||||||
|
EXPECT_EQ(1, actual);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(CMSWindowsClipboardTests, has_withFormatAdded_returnsTrue)
|
||||||
|
{
|
||||||
|
CMSWindowsClipboard clipboard(NULL);
|
||||||
|
clipboard.open(0);
|
||||||
|
clipboard.empty();
|
||||||
|
clipboard.add(IClipboard::kText, "synergy rocks!");
|
||||||
|
|
||||||
|
bool actual = clipboard.has(IClipboard::kText);
|
||||||
|
|
||||||
|
EXPECT_EQ(true, actual);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(CMSWindowsClipboardTests, has_withNoFormats_returnsFalse)
|
||||||
|
{
|
||||||
|
CMSWindowsClipboard clipboard(NULL);
|
||||||
|
clipboard.open(0);
|
||||||
|
clipboard.empty();
|
||||||
|
|
||||||
|
bool actual = clipboard.has(IClipboard::kText);
|
||||||
|
|
||||||
|
EXPECT_EQ(false, actual);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(CMSWindowsClipboardTests, get_withNoFormats_returnsEmpty)
|
||||||
|
{
|
||||||
|
CMSWindowsClipboard clipboard(NULL);
|
||||||
|
clipboard.open(0);
|
||||||
|
clipboard.empty();
|
||||||
|
|
||||||
|
CString actual = clipboard.get(IClipboard::kText);
|
||||||
|
|
||||||
|
EXPECT_EQ("", actual);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(CMSWindowsClipboardTests, get_withFormatAdded_returnsExpected)
|
||||||
|
{
|
||||||
|
CMSWindowsClipboard clipboard(NULL);
|
||||||
|
clipboard.open(0);
|
||||||
|
clipboard.empty();
|
||||||
|
clipboard.add(IClipboard::kText, "synergy rocks!");
|
||||||
|
|
||||||
|
CString actual = clipboard.get(IClipboard::kText);
|
||||||
|
|
||||||
|
EXPECT_EQ("synergy rocks!", actual);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(CMSWindowsClipboardTests, isOwnedBySynergy_defaultState_noError)
|
||||||
|
{
|
||||||
|
CMSWindowsClipboard clipboard(NULL);
|
||||||
|
clipboard.open(0);
|
||||||
|
|
||||||
|
bool actual = clipboard.isOwnedBySynergy();
|
||||||
|
|
||||||
|
EXPECT_EQ(true, actual);
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue