symbian-qemu-0.9.1-12/python-2.6.1/Lib/test/test_applesingle.py
changeset 1 2fb8b9db1c86
equal deleted inserted replaced
0:ffa851df0825 1:2fb8b9db1c86
       
     1 # Copyright (C) 2003 Python Software Foundation
       
     2 
       
     3 import unittest
       
     4 import macostools
       
     5 import Carbon.File
       
     6 import MacOS
       
     7 import os
       
     8 from test import test_support
       
     9 import struct
       
    10 import applesingle
       
    11 
       
    12 AS_MAGIC=0x00051600
       
    13 AS_VERSION=0x00020000
       
    14 dataforkdata = 'hello\r\0world\n'
       
    15 resourceforkdata = 'goodbye\ncruel\0world\r'
       
    16 
       
    17 applesingledata = struct.pack(">ll16sh", AS_MAGIC, AS_VERSION, "foo", 2) + \
       
    18     struct.pack(">llllll", 1, 50, len(dataforkdata),
       
    19         2, 50+len(dataforkdata), len(resourceforkdata)) + \
       
    20     dataforkdata + \
       
    21     resourceforkdata
       
    22 TESTFN2 = test_support.TESTFN + '2'
       
    23 
       
    24 class TestApplesingle(unittest.TestCase):
       
    25 
       
    26     def setUp(self):
       
    27         fp = open(test_support.TESTFN, 'w')
       
    28         fp.write(applesingledata)
       
    29         fp.close()
       
    30 
       
    31     def tearDown(self):
       
    32         try:
       
    33             os.unlink(test_support.TESTFN)
       
    34         except:
       
    35             pass
       
    36         try:
       
    37             os.unlink(TESTFN2)
       
    38         except:
       
    39             pass
       
    40 
       
    41     def compareData(self, isrf, data):
       
    42         if isrf:
       
    43             fp = MacOS.openrf(TESTFN2, '*rb')
       
    44         else:
       
    45             fp = open(TESTFN2, 'rb')
       
    46         filedata = fp.read(1000)
       
    47         self.assertEqual(data, filedata)
       
    48 
       
    49     def test_applesingle(self):
       
    50         try:
       
    51             os.unlink(TESTFN2)
       
    52         except:
       
    53             pass
       
    54         applesingle.decode(test_support.TESTFN, TESTFN2)
       
    55         self.compareData(False, dataforkdata)
       
    56         self.compareData(True, resourceforkdata)
       
    57 
       
    58     def test_applesingle_resonly(self):
       
    59         try:
       
    60             os.unlink(TESTFN2)
       
    61         except:
       
    62             pass
       
    63         applesingle.decode(test_support.TESTFN, TESTFN2, resonly=True)
       
    64         self.compareData(False, resourceforkdata)
       
    65 
       
    66 def test_main():
       
    67     test_support.run_unittest(TestApplesingle)
       
    68 
       
    69 
       
    70 if __name__ == '__main__':
       
    71     test_main()