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

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.6)
  3.  
  4. import sys
  5. import os
  6. import struct
  7. import unittest
  8. import copy
  9. import win32con
  10. import pythoncom
  11. from win32com.shell import shell
  12. from win32com.shell.shellcon import *
  13. from win32com.storagecon import *
  14. import win32com.test.util as win32com
  15.  
  16. class ShellTester(win32com.test.util.TestCase):
  17.     
  18.     def testShellLink(self):
  19.         desktop = str(shell.SHGetSpecialFolderPath(0, CSIDL_DESKTOP))
  20.         num = 0
  21.         shellLink = pythoncom.CoCreateInstance(shell.CLSID_ShellLink, None, pythoncom.CLSCTX_INPROC_SERVER, shell.IID_IShellLink)
  22.         persistFile = shellLink.QueryInterface(pythoncom.IID_IPersistFile)
  23.         for base_name in os.listdir(desktop):
  24.             name = os.path.join(desktop, base_name)
  25.             
  26.             try:
  27.                 persistFile.Load(name, STGM_READ)
  28.             except pythoncom.com_error:
  29.                 continue
  30.  
  31.             (fname, findData) = shellLink.GetPath(0)
  32.             unc = shellLink.GetPath(shell.SLGP_UNCPRIORITY)[0]
  33.             num += 1
  34.         
  35.         if num == 0:
  36.             print 'Could not find any links on your desktop, which is unusual'
  37.         
  38.  
  39.     
  40.     def testShellFolder(self):
  41.         sf = shell.SHGetDesktopFolder()
  42.         names_1 = []
  43.         for i in sf:
  44.             name = sf.GetDisplayNameOf(i, SHGDN_NORMAL)
  45.             names_1.append(name)
  46.         
  47.         enum = sf.EnumObjects(0, SHCONTF_FOLDERS | SHCONTF_NONFOLDERS | SHCONTF_INCLUDEHIDDEN)
  48.         names_2 = []
  49.         for i in enum:
  50.             name = sf.GetDisplayNameOf(i, SHGDN_NORMAL)
  51.             names_2.append(name)
  52.         
  53.         names_1.sort()
  54.         names_2.sort()
  55.         self.assertEqual(names_1, names_2)
  56.  
  57.  
  58.  
  59. class PIDLTester(win32com.test.util.TestCase):
  60.     
  61.     def _rtPIDL(self, pidl):
  62.         pidl_str = shell.PIDLAsString(pidl)
  63.         pidl_rt = shell.StringAsPIDL(pidl_str)
  64.         self.assertEqual(pidl_rt, pidl)
  65.         pidl_str_rt = shell.PIDLAsString(pidl_rt)
  66.         self.assertEqual(pidl_str_rt, pidl_str)
  67.  
  68.     
  69.     def _rtCIDA(self, parent, kids):
  70.         cida = (parent, kids)
  71.         cida_str = shell.CIDAAsString(cida)
  72.         cida_rt = shell.StringAsCIDA(cida_str)
  73.         self.assertEqual(cida, cida_rt)
  74.         cida_str_rt = shell.CIDAAsString(cida_rt)
  75.         self.assertEqual(cida_str_rt, cida_str)
  76.  
  77.     
  78.     def testPIDL(self):
  79.         expect = '\x03\x00\x01\x00\x00'
  80.         self.assertEqual(shell.PIDLAsString([
  81.             '\x01']), expect)
  82.         self._rtPIDL([
  83.             '\x00'])
  84.         self._rtPIDL([
  85.             '\x01',
  86.             '\x02',
  87.             '\x03'])
  88.         self._rtPIDL([
  89.             '\x00' * 2048] * 2048)
  90.         self.assertRaises(TypeError, shell.PIDLAsString, 'foo')
  91.  
  92.     
  93.     def testCIDA(self):
  94.         self._rtCIDA([
  95.             '\x00'], [
  96.             [
  97.                 '\x00']])
  98.         self._rtCIDA([
  99.             '\x01'], [
  100.             [
  101.                 '\x02']])
  102.         self._rtCIDA([
  103.             '\x00'], [
  104.             [
  105.                 '\x00'],
  106.             [
  107.                 '\x01'],
  108.             [
  109.                 '\x02']])
  110.  
  111.     
  112.     def testBadShortPIDL(self):
  113.         pidl = '\x01\x00\x01'
  114.         self.assertRaises(ValueError, shell.StringAsPIDL, pidl)
  115.  
  116.  
  117.  
  118. class FILEGROUPDESCRIPTORTester(win32com.test.util.TestCase):
  119.     
  120.     def _testRT(self, fd):
  121.         fgd_string = shell.FILEGROUPDESCRIPTORAsString([
  122.             fd])
  123.         fd2 = shell.StringAsFILEGROUPDESCRIPTOR(fgd_string)[0]
  124.         fd = fd.copy()
  125.         fd2 = fd2.copy()
  126.         if not fd.has_key('dwFlags'):
  127.             del fd2['dwFlags']
  128.         
  129.         if not fd.has_key('cFileName'):
  130.             self.assertEqual(fd2['cFileName'], '')
  131.             del fd2['cFileName']
  132.         
  133.         self.assertEqual(fd, fd2)
  134.  
  135.     
  136.     def testSimple(self):
  137.         fgd = shell.FILEGROUPDESCRIPTORAsString([])
  138.         header = struct.pack('i', 0)
  139.         self.assertEqual(header, fgd[:len(header)])
  140.         self._testRT(dict())
  141.         d = dict()
  142.         fgd = shell.FILEGROUPDESCRIPTORAsString([
  143.             d])
  144.         header = struct.pack('i', 1)
  145.         self.assertEqual(header, fgd[:len(header)])
  146.         self._testRT(d)
  147.  
  148.     
  149.     def testComplex(self):
  150.         if sys.hexversion < 33751040:
  151.             return None
  152.         clsid = pythoncom.MakeIID('{CD637886-DB8B-4b04-98B5-25731E1495BE}')
  153.         d = dict(cFileName = 'foo.txt', clsid = clsid, sizel = (1, 2), pointl = (3, 4), dwFileAttributes = win32con.FILE_ATTRIBUTE_NORMAL, ftCreationTime = pythoncom.MakeTime(10), ftLastAccessTime = pythoncom.MakeTime(11), ftLastWriteTime = pythoncom.MakeTime(12), nFileSize = sys.maxint + 1)
  154.         self._testRT(d)
  155.  
  156.     
  157.     def testUnicode(self):
  158.         if sys.hexversion < 33751040:
  159.             return None
  160.         d = [
  161.             dict(cFileName = u'foo.txt', sizel = (1, 2), pointl = (3, 4), dwFileAttributes = win32con.FILE_ATTRIBUTE_NORMAL, ftCreationTime = pythoncom.MakeTime(10), ftLastAccessTime = pythoncom.MakeTime(11), ftLastWriteTime = pythoncom.MakeTime(12), nFileSize = sys.maxint + 1),
  162.             dict(cFileName = u'foo2.txt', sizel = (1, 2), pointl = (3, 4), dwFileAttributes = win32con.FILE_ATTRIBUTE_NORMAL, ftCreationTime = pythoncom.MakeTime(10), ftLastAccessTime = pythoncom.MakeTime(11), ftLastWriteTime = pythoncom.MakeTime(12), nFileSize = sys.maxint + 1),
  163.             dict(cFileName = u'foo┬⌐.txt', sizel = (1, 2), pointl = (3, 4), dwFileAttributes = win32con.FILE_ATTRIBUTE_NORMAL, ftCreationTime = pythoncom.MakeTime(10), ftLastAccessTime = pythoncom.MakeTime(11), ftLastWriteTime = pythoncom.MakeTime(12), nFileSize = sys.maxint + 1)]
  164.         s = shell.FILEGROUPDESCRIPTORAsString(d, 1)
  165.         d2 = shell.StringAsFILEGROUPDESCRIPTOR(s)
  166.         for t in d2:
  167.             del t['dwFlags']
  168.         
  169.         self.assertEqual(d, d2)
  170.  
  171.  
  172.  
  173. class FileOperationTester(win32com.test.util.TestCase):
  174.     
  175.     def setUp(self):
  176.         import tempfile
  177.         self.src_name = os.path.join(tempfile.gettempdir(), 'pywin32_testshell')
  178.         self.dest_name = os.path.join(tempfile.gettempdir(), 'pywin32_testshell_dest')
  179.         self.test_data = 'Hello from\x00Python'
  180.         f = file(self.src_name, 'wb')
  181.         f.write(self.test_data)
  182.         f.close()
  183.         
  184.         try:
  185.             os.unlink(self.dest_name)
  186.         except os.error:
  187.             pass
  188.  
  189.  
  190.     
  191.     def tearDown(self):
  192.         for fname in (self.src_name, self.dest_name):
  193.             if os.path.isfile(fname):
  194.                 os.unlink(fname)
  195.                 continue
  196.         
  197.  
  198.     
  199.     def testCopy(self):
  200.         s = (0, FO_COPY, self.src_name, self.dest_name)
  201.         (rc, aborted) = shell.SHFileOperation(s)
  202.         self.failUnless(not aborted)
  203.         self.failUnlessEqual(0, rc)
  204.         self.failUnless(os.path.isfile(self.src_name))
  205.         self.failUnless(os.path.isfile(self.dest_name))
  206.  
  207.     
  208.     def testRename(self):
  209.         s = (0, FO_RENAME, self.src_name, self.dest_name)
  210.         (rc, aborted) = shell.SHFileOperation(s)
  211.         self.failUnless(not aborted)
  212.         self.failUnlessEqual(0, rc)
  213.         self.failUnless(os.path.isfile(self.dest_name))
  214.         self.failUnless(not os.path.isfile(self.src_name))
  215.  
  216.     
  217.     def testMove(self):
  218.         s = (0, FO_MOVE, self.src_name, self.dest_name)
  219.         (rc, aborted) = shell.SHFileOperation(s)
  220.         self.failUnless(not aborted)
  221.         self.failUnlessEqual(0, rc)
  222.         self.failUnless(os.path.isfile(self.dest_name))
  223.         self.failUnless(not os.path.isfile(self.src_name))
  224.  
  225.     
  226.     def testDelete(self):
  227.         s = (0, FO_DELETE, self.src_name, None, FOF_NOCONFIRMATION)
  228.         (rc, aborted) = shell.SHFileOperation(s)
  229.         self.failUnless(not aborted)
  230.         self.failUnlessEqual(0, rc)
  231.         self.failUnless(not os.path.isfile(self.src_name))
  232.  
  233.  
  234. if __name__ == '__main__':
  235.     win32com.test.util.testmain()
  236.  
  237.