blob: e60aabacfef6ac72a4d328e399016c84cc6f21a3 [file] [log] [blame]
Nobuaki Sukegawaad835862015-12-23 23:32:09 +09001#
2# Licensed to the Apache Software Foundation (ASF) under one
3# or more contributor license agreements. See the NOTICE file
4# distributed with this work for additional information
5# regarding copyright ownership. The ASF licenses this file
6# to you under the Apache License, Version 2.0 (the
7# "License"); you may not use this file except in compliance
8# with the License. You may obtain a copy of the License at
9#
10# http://www.apache.org/licenses/LICENSE-2.0
11#
12# Unless required by applicable law or agreed to in writing,
13# software distributed under the License is distributed on an
14# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15# KIND, either express or implied. See the License for the
16# specific language governing permissions and limitations
17# under the License.
18#
Phongphan Phuttha7f01e2a2015-11-06 15:46:50 +070019
20import sys
21import unittest
22
Nobuaki Sukegawaad835862015-12-23 23:32:09 +090023import _import_local_thrift
24from thrift.protocol.TJSONProtocol import TJSONProtocol
25from thrift.transport import TTransport
26
Phongphan Phuttha7f01e2a2015-11-06 15:46:50 +070027#
28# In order to run the test under Windows. We need to create symbolic link
29# name 'thrift' to '../src' folder by using:
30#
31# mklink /D thrift ..\src
32#
33
34class TestJSONString(unittest.TestCase):
35
36 def test_escaped_unicode_string(self):
Phongphan Phuttha369d62e2015-11-09 02:05:09 +070037 unicode_json = b'"hello \\u0e01\\u0e02\\u0e03\\ud835\\udcab\\udb40\\udc70 unicode"'
38 unicode_text = u'hello \u0e01\u0e02\u0e03\U0001D4AB\U000E0070 unicode'
Phongphan Phuttha7f01e2a2015-11-06 15:46:50 +070039
40 buf = TTransport.TMemoryBuffer(unicode_json)
41 transport = TTransport.TBufferedTransportFactory().getTransport(buf)
42 protocol = TJSONProtocol(transport)
43
44 if sys.version_info[0] == 2:
45 unicode_text = unicode_text.encode('utf8')
46 self.assertEqual(protocol.readString(), unicode_text)
47
48if __name__ == '__main__':
49 unittest.main()
50