Nobuaki Sukegawa | 8565061 | 2016-01-08 03:26:44 +0900 | [diff] [blame] | 1 | #!/usr/bin/env python |
| 2 | |
| 3 | import argparse |
| 4 | import sys |
| 5 | |
| 6 | from util import add_common_args, init_protocol |
Nobuaki Sukegawa | d479e23 | 2016-02-28 11:28:19 +0900 | [diff] [blame] | 7 | from local_thrift import thrift # noqa |
Nobuaki Sukegawa | 8565061 | 2016-01-08 03:26:44 +0900 | [diff] [blame] | 8 | from thrift.Thrift import TMessageType, TType |
| 9 | |
| 10 | |
| 11 | # TODO: generate from ThriftTest.thrift |
| 12 | def test_string(proto, value): |
Nobuaki Sukegawa | 10308cb | 2016-02-03 01:57:03 +0900 | [diff] [blame] | 13 | method_name = 'testString' |
| 14 | ttype = TType.STRING |
| 15 | proto.writeMessageBegin(method_name, TMessageType.CALL, 3) |
| 16 | proto.writeStructBegin(method_name + '_args') |
| 17 | proto.writeFieldBegin('thing', ttype, 1) |
| 18 | proto.writeString(value) |
| 19 | proto.writeFieldEnd() |
| 20 | proto.writeFieldStop() |
| 21 | proto.writeStructEnd() |
| 22 | proto.writeMessageEnd() |
| 23 | proto.trans.flush() |
Nobuaki Sukegawa | 8565061 | 2016-01-08 03:26:44 +0900 | [diff] [blame] | 24 | |
Nobuaki Sukegawa | 10308cb | 2016-02-03 01:57:03 +0900 | [diff] [blame] | 25 | _, mtype, _ = proto.readMessageBegin() |
| 26 | assert mtype == TMessageType.REPLY |
| 27 | proto.readStructBegin() |
| 28 | _, ftype, fid = proto.readFieldBegin() |
| 29 | assert fid == 0 |
| 30 | assert ftype == ttype |
| 31 | result = proto.readString() |
| 32 | proto.readFieldEnd() |
| 33 | _, ftype, _ = proto.readFieldBegin() |
| 34 | assert ftype == TType.STOP |
| 35 | proto.readStructEnd() |
| 36 | proto.readMessageEnd() |
| 37 | assert value == result |
Nobuaki Sukegawa | 8565061 | 2016-01-08 03:26:44 +0900 | [diff] [blame] | 38 | |
| 39 | |
| 40 | def main(argv): |
Nobuaki Sukegawa | 10308cb | 2016-02-03 01:57:03 +0900 | [diff] [blame] | 41 | p = argparse.ArgumentParser() |
| 42 | add_common_args(p) |
| 43 | p.add_argument('--limit', type=int) |
| 44 | args = p.parse_args() |
| 45 | proto = init_protocol(args) |
| 46 | test_string(proto, 'a' * (args.limit - 1)) |
| 47 | test_string(proto, 'a' * (args.limit - 1)) |
| 48 | print('[OK]: limit - 1') |
| 49 | test_string(proto, 'a' * args.limit) |
| 50 | test_string(proto, 'a' * args.limit) |
| 51 | print('[OK]: just limit') |
| 52 | try: |
| 53 | test_string(proto, 'a' * (args.limit + 1)) |
| 54 | except: |
| 55 | print('[OK]: limit + 1') |
| 56 | else: |
| 57 | print('[ERROR]: limit + 1') |
| 58 | assert False |
Nobuaki Sukegawa | 8565061 | 2016-01-08 03:26:44 +0900 | [diff] [blame] | 59 | |
James E. King, III | 0ad20bd | 2017-09-30 15:44:16 -0700 | [diff] [blame] | 60 | |
Nobuaki Sukegawa | 8565061 | 2016-01-08 03:26:44 +0900 | [diff] [blame] | 61 | if __name__ == '__main__': |
Nobuaki Sukegawa | 10308cb | 2016-02-03 01:57:03 +0900 | [diff] [blame] | 62 | main(sys.argv[1:]) |