home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2010 November / maximum-cd-2010-11.iso / DiscContents / calibre-0.7.13.msi / file_2581 (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2010-08-06  |  5.4 KB  |  139 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.6)
  3.  
  4. import sys
  5. import os
  6. import unittest
  7. from win32clipboard import *
  8. import win32gui
  9. import win32con
  10. import pywintypes
  11. import array
  12. custom_format_name = 'PythonClipboardTestFormat'
  13.  
  14. class CrashingTestCase(unittest.TestCase):
  15.     
  16.     def test_722082(self):
  17.         
  18.         class crasher(object):
  19.             pass
  20.  
  21.         obj = crasher()
  22.         OpenClipboard()
  23.         
  24.         try:
  25.             EmptyClipboard()
  26.             self.assertRaises(TypeError, SetClipboardData, 0, obj)
  27.         finally:
  28.             CloseClipboard()
  29.  
  30.  
  31.  
  32.  
  33. class TestBitmap(unittest.TestCase):
  34.     
  35.     def setUp(self):
  36.         self.bmp_handle = None
  37.         
  38.         try:
  39.             this_file = __file__
  40.         except NameError:
  41.             this_file = sys.argv[0]
  42.  
  43.         this_dir = os.path.dirname(__file__)
  44.         self.bmp_name = os.path.join(os.path.abspath(this_dir), '..', 'Demos', 'images', 'smiley.bmp')
  45.         self.failUnless(os.path.isfile(self.bmp_name))
  46.         flags = win32con.LR_DEFAULTSIZE | win32con.LR_LOADFROMFILE
  47.         self.bmp_handle = win32gui.LoadImage(0, self.bmp_name, win32con.IMAGE_BITMAP, 0, 0, flags)
  48.         self.failUnless(self.bmp_handle, 'Failed to get a bitmap handle')
  49.  
  50.     
  51.     def tearDown(self):
  52.         if self.bmp_handle:
  53.             win32gui.DeleteObject(self.bmp_handle)
  54.         
  55.  
  56.     
  57.     def test_bitmap_roundtrip(self):
  58.         OpenClipboard()
  59.         
  60.         try:
  61.             SetClipboardData(win32con.CF_BITMAP, self.bmp_handle)
  62.             got_handle = GetClipboardDataHandle(win32con.CF_BITMAP)
  63.             self.failUnlessEqual(got_handle, self.bmp_handle)
  64.         finally:
  65.             CloseClipboard()
  66.  
  67.  
  68.  
  69.  
  70. class TestStrings(unittest.TestCase):
  71.     
  72.     def setUp(self):
  73.         OpenClipboard()
  74.  
  75.     
  76.     def tearDown(self):
  77.         CloseClipboard()
  78.  
  79.     
  80.     def test_unicode(self):
  81.         val = unicode('test-\xe0\xf2', 'mbcs')
  82.         SetClipboardData(win32con.CF_UNICODETEXT, val)
  83.         self.failUnlessEqual(GetClipboardData(win32con.CF_UNICODETEXT), val)
  84.  
  85.     
  86.     def test_unicode_text(self):
  87.         val = 'test-val'
  88.         SetClipboardText(val)
  89.         self.failUnlessEqual(GetClipboardData(win32con.CF_TEXT), val)
  90.  
  91.     
  92.     def test_string(self):
  93.         val = 'test'
  94.         SetClipboardData(win32con.CF_TEXT, val)
  95.         self.failUnlessEqual(GetClipboardData(win32con.CF_TEXT), val)
  96.  
  97.  
  98.  
  99. class TestGlobalMemory(unittest.TestCase):
  100.     
  101.     def setUp(self):
  102.         OpenClipboard()
  103.  
  104.     
  105.     def tearDown(self):
  106.         CloseClipboard()
  107.  
  108.     
  109.     def test_mem(self):
  110.         val = 'test'
  111.         SetClipboardData(win32con.CF_TEXT, val)
  112.         raw_data = GetGlobalMemory(GetClipboardDataHandle(win32con.CF_TEXT))
  113.         self.failUnlessEqual(val + '\x00', raw_data)
  114.  
  115.     
  116.     def test_bad_mem(self):
  117.         if sys.getwindowsversion()[0] > 5:
  118.             print 'skipping test_bad_mem - fails on Vista (x64 at least - not sure about x32...)'
  119.             return None
  120.         self.failUnlessRaises(pywintypes.error, GetGlobalMemory, 0)
  121.         self.failUnlessRaises(pywintypes.error, GetGlobalMemory, 1)
  122.         self.failUnlessRaises(pywintypes.error, GetGlobalMemory, -1)
  123.  
  124.     
  125.     def test_custom_mem(self):
  126.         test_data = 'hello\x00\xff'
  127.         test_buffer = array.array('c', test_data)
  128.         cf = RegisterClipboardFormat(custom_format_name)
  129.         self.failUnlessEqual(custom_format_name, GetClipboardFormatName(cf))
  130.         SetClipboardData(cf, test_buffer)
  131.         hglobal = GetClipboardDataHandle(cf)
  132.         data = GetGlobalMemory(hglobal)
  133.         self.failUnlessEqual(data, test_data)
  134.  
  135.  
  136. if __name__ == '__main__':
  137.     unittest.main()
  138.  
  139.