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