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