diff Resources/EncodingTests.py @ 1090:e494ceb8d763

support more encodings
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 05 Aug 2014 12:04:23 +0200
parents 6fd4434c1bcf
children a66224eec125
line wrap: on
line diff
--- a/Resources/EncodingTests.py	Tue Aug 05 08:49:25 2014 +0200
+++ b/Resources/EncodingTests.py	Tue Aug 05 12:04:23 2014 +0200
@@ -1,7 +1,7 @@
 #!/usr/bin/python
 # -*- coding: utf-8 -*-
 
-source = u'éäöòДΘĝדصķћ'
+source = u'éäöòДΘĝדصķћ๛ネİ'
 
 encodings = {
     'UTF-8' : 'Utf8',
@@ -15,8 +15,16 @@
     'ISO-8859-6' : 'Arabic',
     'ISO-8859-7' : 'Greek',
     'ISO-8859-8' : 'Hebrew',
+    'TIS-620' : 'Thai',
+    'SHIFT-JIS' : 'Japanese',
+    #'GB18030' : 'Chinese',
 }
 
+#from encodings.aliases import aliases
+#for a, b in aliases.iteritems():
+#    print '%s : %s' % (a, b)
+
+
 # "63" corresponds to "?"
 l = []
 encoded = []
@@ -30,12 +38,24 @@
     
 
 for encoding, orthancEnumeration in encodings.iteritems():
-    l.append('Orthanc::Encoding_%s' % orthancEnumeration)
-    s = source.encode(encoding, 'replace')
+    l.append('::Orthanc::Encoding_%s' % orthancEnumeration)
+    s = source.encode(encoding, 'ignore')
     encoded.append(ToArray(s))
     expected.append(ToArray(s.decode(encoding).encode('utf-8')))
 
-print 'static const unsigned int testEncodingsCount = %d;' % len(encodings)
-print 'static const Orthanc::Encoding testEncodings[] = {\n  %s\n};' % (',\n  '.join(l))
-print 'static const char *testEncodingsEncoded[%d] = {\n  %s\n};' % (len(encodings), ',\n  '.join(encoded))
-print 'static const char *testEncodingsExpected[%d] = {\n  %s\n};' % (len(encodings), ',\n  '.join(expected))
+
+# https://en.wikipedia.org/wiki/GB_18030#Technical_details
+l.append('::Orthanc::Encoding_Chinese')
+expected.append(ToArray('Þßàáâã'))
+encoded.append('"\\x81\\x30\\x89\\x37\\x81\\x30\\x89\\x38\\xA8\\xA4\\xA8\\xA2\\x81\\x30\\x89\\x39\\x81\\x30\\x8A\\x30"')
+
+
+if True:
+    print 'static const unsigned int testEncodingsCount = %d;' % len(l)
+    print 'static const ::Orthanc::Encoding testEncodings[] = {\n  %s\n};' % (',\n  '.join(l))
+    print 'static const char *testEncodingsEncoded[%d] = {\n  %s\n};' % (len(l), ',\n  '.join(encoded))
+    print 'static const char *testEncodingsExpected[%d] = {\n  %s\n};' % (len(l), ',\n  '.join(expected))
+else:
+    for i in range(len(expected)):
+        print expected[i]
+        #print '%s: %s' % (expected[i], l[i])