1(*
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*)
19
20open Thrift;;
21open ThriftTest_types;;
22
23let s = new TSocket.t "127.0.0.1" 9090;;
24let p = new TBinaryProtocol.t s;;
25let c = new ThriftTest.client p p;;
26let sod = function
27    Some v -> v
28  | None -> raise Thrift_error;;
29
30s#opn;
31print_string (c#testString "bya");
32print_char '\n';
33print_int (c#testByte 8);
34print_char '\n';
35print_int (c#testByte (-8));
36print_char '\n';
37print_int (c#testI32 32);
38print_char '\n';
39print_string (Int64.to_string (c#testI64 64L));
40print_char '\n';
41print_float (c#testDouble 3.14);
42print_char '\n';
43
44let l = [1;2;3;4] in
45  if l = (c#testList l) then print_string "list ok\n" else print_string "list fail\n";;
46let h = Hashtbl.create 5 in
47let a = Hashtbl.add h in
48  for i=1 to 10 do
49    a i (10*i)
50  done;
51  let r = c#testMap h in
52    for i=1 to 10 do
53      try
54        let g = Hashtbl.find r i in
55          print_int i;
56          print_char ' ';
57          print_int g;
58          print_char '\n'
59      with Not_found -> print_string ("Can't find "^(string_of_int i)^"\n")
60    done;;
61
62let s = Hashtbl.create 5 in
63let a = Hashtbl.add s in
64  for i = 1 to 10 do
65    a i true
66  done;
67  let r = c#testSet s in
68    for i = 1 to 10 do
69      try
70        let g = Hashtbl.find r i in
71          print_int i;
72          print_char '\n'
73      with Not_found -> print_string ("Can't find "^(string_of_int i)^"\n")
74    done;;
75try
76  c#testException "Xception"
77with Xception _ -> print_string "testException ok\n";;
78try
79  ignore(c#testMultiException "Xception" "bya")
80with Xception e -> Printf.printf "%d %s\n" (sod e#get_errorCode) (sod e#get_message);;
81
82
83