Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 103 lines (83 sloc) 3.492 kb
f3b935b Thomas Gazagnaire Import http://xenbits.xen.org/xapi/xen-api-libs.hg?file/8df716c248d1/rpc...
authored
1 (*
2 * Copyright (C) 2006-2009 Citrix Systems Inc.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License as published
6 * by the Free Software Foundation; version 2.1 only. with the special
7 * exception on linking described in file LICENSE.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU Lesser General Public License for more details.
13 *)
14
15 type t = Foo of int | Bar of (int * float) with rpc
16
17 module M = struct
18 type m = t with rpc
19 end
20
21 type 'a x = {
22 foo: M.m;
23 bar: string;
24 gna: float list;
25 f1: (int option * bool list * float list list) option;
26 f2: (string * string list) array;
27 f3: int32;
28 f4: int64;
29 f5: int;
30 f6: (unit * char) list;
31 f7: 'a list;
32 progress: int array;
70d4607 Thomas Gazagnaire Add an (optional) mapping between field names
authored
33 } with rpc ("f5" -> "type", "f7" -> "let")
f3b935b Thomas Gazagnaire Import http://xenbits.xen.org/xapi/xen-api-libs.hg?file/8df716c248d1/rpc...
authored
34
35 let _ =
36 let x = {
37 foo= Foo 3;
38 bar= "ha ha";
f82b784 Thomas Gazagnaire Import patch from @djs55 <dave.scott@citrix.com>
authored
39 gna=[1.; 2.; 3.; 4.; Unix.gettimeofday () ];
f3b935b Thomas Gazagnaire Import http://xenbits.xen.org/xapi/xen-api-libs.hg?file/8df716c248d1/rpc...
authored
40 f2 = [| "hi",["hi"]; "hou",["hou";"hou"]; "foo", ["b";"a";"r"] |];
41 f1 = Some (None, [true], [[1.]; [2.;3.]]);
42 f3 = Int32.max_int;
43 f4 = Int64.max_int;
44 f5 = max_int;
45 f6 = [ (),'a' ; (),'b' ; (),'c'; (),'d' ; (),'e' ];
46 f7 = [ Foo 1; Foo 2; Foo 3 ];
47 progress = [| 0; 1; 2; 3; 4; 5 |];
48 } in
49
50 (* Testing basic marshalling/unmarshalling *)
51
52 let rpc = rpc_of_x M.rpc_of_m x in
53
54 let rpc_xml = Xmlrpc.to_string rpc in
55 let rpc_json = Jsonrpc.to_string rpc in
56
57 Printf.printf "\n==rpc_xml==\n%s\n" rpc_xml;
58 Printf.printf "\n==json==\n%s\n" rpc_json;
59
60 let callback fields value = match (fields, value) with
61 | ["progress"], Rpc.Int i -> Printf.printf "Progress: %Ld\n" i
62 | _ -> ()
63 in
64 let x_xml = x_of_rpc M.m_of_rpc (Xmlrpc.of_string ~callback rpc_xml) in
65 let x_json = x_of_rpc M.m_of_rpc (Jsonrpc.of_string rpc_json) in
66
67 Printf.printf "\n==Sanity check 1==\nx=x_xml: %b\nx=x_json: %b\n" (x = x_xml) (x = x_json);
68 assert (x = x_xml && x = x_json);
69
70 (* Testing calls and responses *)
71
72 let call = Rpc.call "foo" [ rpc; Rpc.String "Mouhahahaaaaa" ] in
73 let success = Rpc.success rpc in
74 let failure = Rpc.failure rpc in
75
76 let c_xml_str = Xmlrpc.string_of_call call in
77 let s_xml_str = Xmlrpc.string_of_response success in
78 let f_xml_str = Xmlrpc.string_of_response failure in
79
80 let c_json_str = Jsonrpc.string_of_call call in
81 let s_json_str = Jsonrpc.string_of_response success in
82 let f_json_str = Jsonrpc.string_of_response failure in
83
84 Printf.printf "\n==call==\n %s\n%s\n" c_xml_str c_json_str;
85 Printf.printf "\n==success==\n %s\n%s\n" s_xml_str s_json_str;
86 Printf.printf "\n==failure==\n %s\n%s\n" f_xml_str f_json_str;
87
88 let c_xml = Xmlrpc.call_of_string c_xml_str in
89 let s_xml = Xmlrpc.response_of_string s_xml_str in
90 let f_xml = Xmlrpc.response_of_string f_xml_str in
91
0866e3e Thomas Gazagnaire Uncomment tests
authored
92 Printf.printf "\n==Sanity check 2==\ncall=c_xml: %b\nsuccess=s_xml: %b\nfailure=f_xml: %b\n"
f3b935b Thomas Gazagnaire Import http://xenbits.xen.org/xapi/xen-api-libs.hg?file/8df716c248d1/rpc...
authored
93 (call = c_xml) (success = s_xml) (failure = f_xml);
0866e3e Thomas Gazagnaire Uncomment tests
authored
94 assert (call = c_xml && success = s_xml && failure = f_xml);
f3b935b Thomas Gazagnaire Import http://xenbits.xen.org/xapi/xen-api-libs.hg?file/8df716c248d1/rpc...
authored
95
96 let c_json = Jsonrpc.call_of_string c_json_str in
97 let s_json = Jsonrpc.response_of_string s_json_str in
98 let f_json = Jsonrpc.response_of_string f_json_str in
99
100 Printf.printf "\n==Sanity check 3==\ncall=c_json': %b\nsuccess=s_json': %b\nfailure=f_json': %b\n"
101 (call = c_json) (success = s_json) (failure = f_json);
102 assert (call = c_json && success = s_json && failure = f_json)
Something went wrong with that request. Please try again.