comparison OrthancFramework/Resources/CodeGeneration/EncodingTests.py @ 4044:d25f4c0fa160 framework

splitting code into OrthancFramework and OrthancServer
author Sebastien Jodogne <s.jodogne@gmail.com>
date Wed, 10 Jun 2020 20:30:34 +0200
parents Resources/EncodingTests.py@55c900a5b0e4
children
comparison
equal deleted inserted replaced
4043:6c6239aec462 4044:d25f4c0fa160
1 #!/usr/bin/python
2 # -*- coding: utf-8 -*-
3
4 source = u'TestéäöòДΘĝדصķћ๛ネİ'
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 'WINDOWS-1251' : 'Windows1251',
16 'ISO-8859-6' : 'Arabic',
17 'ISO-8859-7' : 'Greek',
18 'ISO-8859-8' : 'Hebrew',
19 'TIS-620' : 'Thai',
20 'SHIFT-JIS' : 'Japanese',
21 #'GB18030' : 'Chinese', # Done manually below (*)
22 }
23
24 #from encodings.aliases import aliases
25 #for a, b in aliases.iteritems():
26 # print '%s : %s' % (a, b)
27
28
29 # "63" corresponds to "?"
30 l = []
31 encoded = []
32 expected = []
33
34 def ToArray(source):
35 result = ''
36 for byte in bytearray(source):
37 result += '\\x%02x' % byte
38 return '"%s"' % result
39
40
41 for encoding, orthancEnumeration in encodings.iteritems():
42 l.append('::Orthanc::Encoding_%s' % orthancEnumeration)
43 s = source.encode(encoding, 'ignore')
44 encoded.append(ToArray(s))
45 expected.append(ToArray(s.decode(encoding).encode('utf-8')))
46
47
48 # https://en.wikipedia.org/wiki/GB_18030#Technical_details (*)
49 l.append('::Orthanc::Encoding_Chinese')
50 expected.append(ToArray('Þßàáâã'))
51 encoded.append('"\\x81\\x30\\x89\\x37\\x81\\x30\\x89\\x38\\xA8\\xA4\\xA8\\xA2\\x81\\x30\\x89\\x39\\x81\\x30\\x8A\\x30"')
52
53 # Issue 32
54 # "encoded" is the copy/paste from "dcm2xml +Ca cyrillic Issue32.dcm"
55 l.append('::Orthanc::Encoding_Windows1251')
56 encoded.append('"\\xd0\\xe5\\xed\\xf2\\xe3\\xe5\\xed\\xee\\xe3\\xf0\\xe0\\xf4\\xe8\\xff"')
57 expected.append(ToArray('Рентгенография'))
58 l.append('::Orthanc::Encoding_Windows1251')
59 encoded.append('"\\xD2\\xE0\\xE7"')
60 expected.append(ToArray('Таз'))
61 l.append('::Orthanc::Encoding_Windows1251')
62 encoded.append('"\\xcf\\xf0\\xff\\xec\\xe0\\xff"')
63 expected.append(ToArray('Прямая'))
64
65
66 if True:
67 print 'static const unsigned int testEncodingsCount = %d;' % len(l)
68 print 'static const ::Orthanc::Encoding testEncodings[] = {\n %s\n};' % (',\n '.join(l))
69 print 'static const char *testEncodingsEncoded[%d] = {\n %s\n};' % (len(l), ',\n '.join(encoded))
70 print 'static const char *testEncodingsExpected[%d] = {\n %s\n};' % (len(l), ',\n '.join(expected))
71 else:
72 for i in range(len(expected)):
73 print expected[i]
74 #print '%s: %s' % (expected[i], l[i])
75
76
77
78 u = (u'grüßEN SébasTIen %s' % source)
79 print 'static const char *toUpperSource = %s;' % ToArray(u.encode('utf-8'))
80 print 'static const char *toUpperResult = %s;' % ToArray(u.upper().encode('utf-8'))