blob: a5f8c1d66b4e566a282b7265f7f9d91636fbdb2c [file] [log] [blame]
Nobuaki Sukegawa85650612016-01-08 03:26:44 +09001#!/usr/bin/env python
2
Jens Geyer72a714e2025-08-26 22:12:07 +02003#
4# Licensed to the Apache Software Foundation (ASF) under one
5# or more contributor license agreements. See the NOTICE file
6# distributed with this work for additional information
7# regarding copyright ownership. The ASF licenses this file
8# to you under the Apache License, Version 2.0 (the
9# "License"); you may not use this file except in compliance
10# with the License. You may obtain a copy of the License at
11#
12# http://www.apache.org/licenses/LICENSE-2.0
13#
14# Unless required by applicable law or agreed to in writing,
15# software distributed under the License is distributed on an
16# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17# KIND, either express or implied. See the License for the
18# specific language governing permissions and limitations
19# under the License.
20#
21
Nobuaki Sukegawa85650612016-01-08 03:26:44 +090022import argparse
23import sys
24
25from util import add_common_args, init_protocol
Nobuaki Sukegawad479e232016-02-28 11:28:19 +090026from local_thrift import thrift # noqa
Nobuaki Sukegawa85650612016-01-08 03:26:44 +090027from thrift.Thrift import TMessageType, TType
28
29
30# TODO: generate from ThriftTest.thrift
31def test_string(proto, value):
Nobuaki Sukegawa10308cb2016-02-03 01:57:03 +090032 method_name = 'testString'
33 ttype = TType.STRING
34 proto.writeMessageBegin(method_name, TMessageType.CALL, 3)
35 proto.writeStructBegin(method_name + '_args')
36 proto.writeFieldBegin('thing', ttype, 1)
37 proto.writeString(value)
38 proto.writeFieldEnd()
39 proto.writeFieldStop()
40 proto.writeStructEnd()
41 proto.writeMessageEnd()
42 proto.trans.flush()
Nobuaki Sukegawa85650612016-01-08 03:26:44 +090043
Nobuaki Sukegawa10308cb2016-02-03 01:57:03 +090044 _, mtype, _ = proto.readMessageBegin()
45 assert mtype == TMessageType.REPLY
46 proto.readStructBegin()
47 _, ftype, fid = proto.readFieldBegin()
48 assert fid == 0
49 assert ftype == ttype
50 result = proto.readString()
51 proto.readFieldEnd()
52 _, ftype, _ = proto.readFieldBegin()
53 assert ftype == TType.STOP
54 proto.readStructEnd()
55 proto.readMessageEnd()
56 assert value == result
Nobuaki Sukegawa85650612016-01-08 03:26:44 +090057
58
59def main(argv):
Nobuaki Sukegawa10308cb2016-02-03 01:57:03 +090060 p = argparse.ArgumentParser()
61 add_common_args(p)
62 p.add_argument('--limit', type=int)
63 args = p.parse_args()
64 proto = init_protocol(args)
65 test_string(proto, 'a' * (args.limit - 1))
66 test_string(proto, 'a' * (args.limit - 1))
67 print('[OK]: limit - 1')
68 test_string(proto, 'a' * args.limit)
69 test_string(proto, 'a' * args.limit)
70 print('[OK]: just limit')
71 try:
72 test_string(proto, 'a' * (args.limit + 1))
James E. King, III350fe752017-10-25 09:57:18 -040073 except Exception:
Nobuaki Sukegawa10308cb2016-02-03 01:57:03 +090074 print('[OK]: limit + 1')
75 else:
76 print('[ERROR]: limit + 1')
77 assert False
Nobuaki Sukegawa85650612016-01-08 03:26:44 +090078
James E. King, III0ad20bd2017-09-30 15:44:16 -070079
Nobuaki Sukegawa85650612016-01-08 03:26:44 +090080if __name__ == '__main__':
Nobuaki Sukegawa10308cb2016-02-03 01:57:03 +090081 main(sys.argv[1:])