author | robin <robin@reportlab.com> |
Tue, 07 Mar 2017 10:00:34 +0000 | |
changeset 4330 | 617ffa6bbdc8 |
parent 4252 | fe660f227cac |
child 4367 | 9960d82643bf |
permissions | -rw-r--r-- |
4330 | 1 |
#Copyright ReportLab Europe Ltd. 2000-2017 |
2963 | 2 |
#see license.txt for license details |
3 |
"""Tests for utility functions in reportlab.pdfbase.pdfutils. |
|
4 |
""" |
|
4252 | 5 |
__version__='3.3.0' |
2984 | 6 |
from reportlab.lib.testutils import setOutDir,makeSuiteForClasses, printLocation |
7 |
setOutDir(__name__) |
|
2963 | 8 |
import os |
2966 | 9 |
import unittest |
2963 | 10 |
from reportlab.pdfbase.pdfutils import _AsciiHexEncode, _AsciiHexDecode |
3842 | 11 |
from reportlab.pdfbase.pdfutils import asciiBase85Encode, asciiBase85Decode |
4003
623f585f5fbc
test_rl_accel.py & test_pdfbase_pdfutils.py : fix for new a85 decode output
robin
parents:
3842
diff
changeset
|
12 |
from reportlab.lib.utils import asBytes |
2963 | 13 |
|
14 |
class PdfEncodingTestCase(unittest.TestCase): |
|
15 |
"Test various encodings used in PDF files." |
|
16 |
||
17 |
def testAsciiHex(self): |
|
18 |
"Test if the obvious test for whether ASCII-Hex encoding works." |
|
19 |
||
20 |
plainText = 'What is the average velocity of a sparrow?' |
|
21 |
encoded = _AsciiHexEncode(plainText) |
|
22 |
decoded = _AsciiHexDecode(encoded) |
|
23 |
||
24 |
msg = "Round-trip AsciiHex encoding failed." |
|
25 |
assert decoded == plainText, msg |
|
26 |
||
27 |
||
28 |
def testAsciiBase85(self): |
|
29 |
"Test if the obvious test for whether ASCII-Base85 encoding works." |
|
30 |
||
31 |
msg = "Round-trip AsciiBase85 encoding failed." |
|
32 |
plain = 'What is the average velocity of a sparrow?' |
|
33 |
||
34 |
#the remainder block can be absent or from 1 to 4 bytes |
|
4003
623f585f5fbc
test_rl_accel.py & test_pdfbase_pdfutils.py : fix for new a85 decode output
robin
parents:
3842
diff
changeset
|
35 |
for i in xrange(256): |
3842 | 36 |
encoded = asciiBase85Encode(plain) |
37 |
decoded = asciiBase85Decode(encoded) |
|
4003
623f585f5fbc
test_rl_accel.py & test_pdfbase_pdfutils.py : fix for new a85 decode output
robin
parents:
3842
diff
changeset
|
38 |
assert decoded == asBytes(plain,'latin1'), msg |
623f585f5fbc
test_rl_accel.py & test_pdfbase_pdfutils.py : fix for new a85 decode output
robin
parents:
3842
diff
changeset
|
39 |
plain += chr(i) |
2963 | 40 |
|
41 |
def makeSuite(): |
|
42 |
return makeSuiteForClasses(PdfEncodingTestCase) |
|
43 |
||
44 |
||
45 |
#noruntests |
|
46 |
if __name__ == "__main__": |
|
47 |
unittest.TextTestRunner().run(makeSuite()) |
|
48 |
printLocation() |