annotate Resources/EncodingTests.py @ 1089:5ea0b56e850d

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