comparison Resources/EncodingTests.py @ 1088:6fd4434c1bcf

unit tests for encodings
author Sebastien Jodogne <s.jodogne@gmail.com>
date Mon, 04 Aug 2014 19:24:28 +0200
parents
children e494ceb8d763
comparison
equal deleted inserted replaced
1087:e07b90fb00eb 1088:6fd4434c1bcf
1 #!/usr/bin/python
2 # -*- coding: utf-8 -*-
3
4 source = u'éäöòДΘĝדصķћ'
5
6 encodings = {
7 'UTF-8' : 'Utf8',
8 'ASCII' : 'Ascii',
9 'ISO-8859-1' : 'Latin1',
10 'ISO-8859-2' : 'Latin2',
11 'ISO-8859-3' : 'Latin3',
12 'ISO-8859-4' : 'Latin4',
13 'ISO-8859-9' : 'Latin5',
14 'ISO-8859-5' : 'Cyrillic',
15 'ISO-8859-6' : 'Arabic',
16 'ISO-8859-7' : 'Greek',
17 'ISO-8859-8' : 'Hebrew',
18 }
19
20 # "63" corresponds to "?"
21 l = []
22 encoded = []
23 expected = []
24
25 def ToArray(source):
26 result = ''
27 for byte in bytearray(source):
28 result += '\\x%02x' % byte
29 return '"%s"' % result
30
31
32 for encoding, orthancEnumeration in encodings.iteritems():
33 l.append('Orthanc::Encoding_%s' % orthancEnumeration)
34 s = source.encode(encoding, 'replace')
35 encoded.append(ToArray(s))
36 expected.append(ToArray(s.decode(encoding).encode('utf-8')))
37
38 print 'static const unsigned int testEncodingsCount = %d;' % len(encodings)
39 print 'static const Orthanc::Encoding testEncodings[] = {\n %s\n};' % (',\n '.join(l))
40 print 'static const char *testEncodingsEncoded[%d] = {\n %s\n};' % (len(encodings), ',\n '.join(encoded))
41 print 'static const char *testEncodingsExpected[%d] = {\n %s\n};' % (len(encodings), ',\n '.join(expected))