-
-
Notifications
You must be signed in to change notification settings - Fork 8
/
test-iso.py
executable file
·181 lines (146 loc) · 6.37 KB
/
test-iso.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
#!/usr/bin/env python
# Copyright (C) 2015 Rocky Bernstein <[email protected]>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
"""Unit test for iso9660
Test some low-level ISO9660 routines
This is basically the same thing as libcdio's testiso9660.c"""
import unittest, sys, os
libdir = os.path.join(os.path.dirname(__file__), '..')
if libdir[-1] != os.path.sep:
libdir += os.path.sep
testdir = os.path.dirname(__file__)
sys.path.insert(0, libdir)
import pyiso9660
import iso9660
def is_eq(a, b):
if len(a) != len(b): return False
for i in range(len(a)):
if a[i] != b[i]:
print("position %d: %d != %d\n" % (i, a[i], b[i]))
return False
return True
achars = ('!', '"', '%', '&', '(', ')', '*', '+', ',', '-', '.',
'/', '?', '<', '=', '>')
class ISO9660Tests(unittest.TestCase):
def test_chars(self):
"""Test ACHAR and DCHAR"""
bad = 0
c=ord('A')
while c<=ord('Z'):
if not pyiso9660.is_dchar(c):
print("Failed iso9660_is_achar test on %c" % c)
bad += 1
if not pyiso9660.is_achar(c):
print("Failed iso9660_is_achar test on %c" % c)
bad += 1
c += 1
self.assertEqual(True, bad==0, 'is_dchar & is_achar A..Z')
bad=0
c=ord('0')
while c<=ord('9'):
if not pyiso9660.is_dchar(c):
print("Failed iso9660_is_dchar test on %c" % c)
bad += 1
if not pyiso9660.is_achar(c):
print("Failed iso9660_is_achar test on %c" % c)
bad += 1
c += 1
self.assertEqual(True, bad==0, 'is_dchar & is_achar 0..9')
bad=0
i=0
while i<=13:
c=ord(achars[i])
if pyiso9660.is_dchar(c):
print("Should not pass is_dchar test on %c" % c)
bad += 1
if not pyiso9660.is_achar(c):
print("Failed is_achar test on symbol %c" % c)
bad += 1
i += 1
self.assertEqual(True, bad==0, 'is_dchar & is_achar symbols')
def test_strncpy_pad(self):
"""Test pyiso9660.strncpy_pad"""
dst = pyiso9660.strncpy_pad("1_3", 5, pyiso9660.DCHARS)
self.assertEqual(dst, "1_3 ", "strncpy_pad DCHARS")
dst = pyiso9660.strncpy_pad("ABC!123", 2, pyiso9660.ACHARS)
self.assertEqual(dst, "AB", "strncpy_pad ACHARS truncation")
def test_dirname(self):
"""Test pyiso9660.dirname_valid_p"""
self.assertEqual(False, pyiso9660.dirname_valid_p("/NOGOOD"),
"dirname_valid_p - /NOGOOD is no good.")
self.assertEqual(False,
pyiso9660.dirname_valid_p("LONGDIRECTORY/NOGOOD"),
"pyiso9660.dirname_valid_p - too long directory")
self.assertEqual(True, pyiso9660.dirname_valid_p("OKAY/DIR"),
"dirname_valid_p - OKAY/DIR should pass ")
self.assertEqual(False, pyiso9660.dirname_valid_p("OKAY/FILE.EXT"),
"pyiso9660.dirname_valid_p - OKAY/FILENAME.EXT")
def test_image_info(self):
"""Test retrieving image information"""
# The test ISO 9660 image
image_fname=os.path.join(testdir, "copying.iso")
iso = iso9660.ISO9660.IFS(source=image_fname)
self.assertNotEqual(iso, None, "Opening %s" % image_fname)
self.assertEqual(iso.get_application_id(),
"MKISOFS ISO 9660/HFS FILESYSTEM BUILDER & CDRECORD CD-R/DVD CREATOR (C) 1993 E.YOUNGDALE (C) 1997 J.PEARSON/J.SCHILLING",
"get_application_id()")
self.assertEqual(iso.get_system_id(), "LINUX",
"get_system_id() eq 'LINUX'")
self.assertEqual(iso.get_volume_id(), "CDROM",
"get_volume_id() eq 'CDROM'")
file_stats = iso.readdir('/')
okay_stats = [
['.', 23, 2048, 1, 2],
['..', 23, 2048, 1, 2],
['COPYING.;1', 24, 17992, 9, 1]
]
self.assertEqual(file_stats, okay_stats, "file stat info")
def test_pathname_valid(self):
"""Test pyiso9660.pathname_valid_p"""
self.assertEqual(True, pyiso9660.pathname_valid_p("OKAY/FILE.EXT"),
"pyiso9660.dirname_valid_p - OKAY/FILE.EXT ")
self.assertEqual(False,
pyiso9660.pathname_valid_p("OKAY/FILENAMELONG.EXT"),
'invalid pathname, long basename')
self.assertEqual(False,
pyiso9660.pathname_valid_p("OKAY/FILE.LONGEXT"),
"pathname_valid_p - long extension" )
dst = pyiso9660.pathname_isofy("this/file.ext", 1)
self.assertNotEqual(dst, "this/file.ext1", "iso9660_pathname_isofy")
def test_time(self):
"""Test time"""
import time
tm = time.localtime(0)
dtime = pyiso9660.set_dtime(tm[0], tm[1], tm[2], tm[3], tm[4], tm[5])
new_tm = pyiso9660.get_dtime(dtime, True)
### FIXME Don't know why the discrepancy, but there is an hour
### difference, perhaps daylight savings time.
### Versions before 0.77 have other bugs.
if new_tm is not None:
# if pyiso9660.VERSION_NUM < 77: new_tm[3] = tm[3]
new_tm[3] = tm[3]
self.assertEqual(True, is_eq(new_tm, tm), 'get_dtime(set_dtime())')
else:
self.assertEqual(True, False, 'get_dtime is None')
# if pyiso9660.VERSION_NUM >= 77:
# tm = time.gmtime(0)
# ltime = pyiso9660.set_ltime(tm[0], tm[1], tm[2], tm[3], tm[4],
# tm[5])
# new_tm = pyiso9660.get_ltime(ltime)
# self.assertEqual(True, is_eq(new_tm, tm),
# 'get_ltime(set_ltime())')
return
if __name__ == "__main__":
unittest.main()