-
Notifications
You must be signed in to change notification settings - Fork 807
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Clipboard: Remove NUL char addition for non text formats (#2184)
- Loading branch information
1 parent
2dfa2bb
commit ad20c9b
Showing
2 changed files
with
72 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
# tests for win32gui | ||
import unittest | ||
|
||
import win32clipboard | ||
|
||
|
||
class TestGetSetClipboardData(unittest.TestCase): | ||
|
||
def copyData(self, data, format_): | ||
win32clipboard.OpenClipboard() | ||
ret = None | ||
try: | ||
win32clipboard.SetClipboardData(format_, data) | ||
ret = win32clipboard.GetClipboardData(format_) | ||
finally: | ||
win32clipboard.CloseClipboard() | ||
return ret | ||
|
||
def copyText(self, data, format_): | ||
win32clipboard.OpenClipboard() | ||
ret = None | ||
try: | ||
win32clipboard.SetClipboardText(data, format_) | ||
ret = win32clipboard.GetClipboardData(format_) | ||
finally: | ||
win32clipboard.CloseClipboard() | ||
return ret | ||
|
||
def test_data(self): | ||
test_data = { | ||
"Dummy str": win32clipboard.CF_UNICODETEXT, | ||
b"Dummy bytes text": win32clipboard.CF_TEXT, | ||
b"Dummy\x00\xFF bytes": win32clipboard.CF_DIB, | ||
} | ||
for data, fmt in test_data.items(): | ||
self.assertEqual(data, self.copyData(data, fmt)) | ||
test_data = { | ||
"Dummy str": (win32clipboard.CF_TEXT, win32clipboard.CF_DIB), | ||
b"Dummy\x00\xFF bytes": (win32clipboard.CF_UNICODETEXT,), | ||
} | ||
for data, formats in test_data.items(): | ||
for fmt in formats: | ||
self.assertNotEqual(data, self.copyData(data, fmt)) | ||
|
||
def test_text(self): | ||
test_data = { | ||
"Dummy str": win32clipboard.CF_UNICODETEXT, | ||
b"Dummy bytes": win32clipboard.CF_TEXT, | ||
} | ||
for data, fmt in test_data.items(): | ||
self.assertEqual(data, self.copyText(data, fmt)) | ||
self.assertRaises(ValueError, self.copyText, data, win32clipboard.CF_DIB) | ||
s = "Dummy str" | ||
self.assertEqual( | ||
s.encode(), self.copyText(s, win32clipboard.CF_TEXT) | ||
) # @TODO - cfati: Do we want this? | ||
|
||
|
||
if __name__ == "__main__": | ||
unittest.main() |