r19141: add a reasonable subset of the qooxdoo runtime environment, and example appli...
[Samba/ekacnet.git] / swat / apps / qooxdoo-examples / test / RPC_3.html
blob8da024a060bb23af9774efbc9ce864011b7ce113
1 <html>
2 <head>
3 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
4 <title>qooxdoo &raquo; Demo</title>
5 <link type="text/css" rel="stylesheet" href="../../resource/css/layout.css"/>
6 <!--[if IE]>
7 <link type="text/css" rel="stylesheet" href="../../resource/css/layout_ie.css"/>
8 <![endif]-->
9 <script type="text/javascript" src="../../script/qx.js"></script>
10 <script type="text/javascript" src=".qxrpc"></script>
11 <!-- With the above script, the service URL for a J2EE application can be
12 automatically determined, no matter on what path it's deployed. -->
13 </head>
14 <body>
15 <script type="text/javascript" src="../../script/layout.js"></script>
17 <div id="demoDescription">
18 <p>Test for RPC functionality.</p>
19 <p>
20 This test calls a whole set of functions to test each of the primitive
21 data types. The comparison results should all end with ": true", and
22 the last test generates an Application Error (#1000). No other test
23 generates that error, so receiving it means the complete set of tests
24 was run.
25 </p>
26 <p>
27 These functions all use the synchronous interface. You should not use
28 the synchronous interface because with some browsers, the entire browser
29 environment locks up during a synchronous call. If the server hangs for
30 a minute or two, so will the browser! You have been warned.
31 </p>
32 </div>
34 <script type="text/javascript">
35 // qx.Settings.setCustomOfClass("qx.io.remote.RemoteExchange", "enableDebug", true);
36 qx.Settings.setCustomOfClass("qx.io.Json", "enableDebug", true);
38 qx.core.Init.getInstance().defineMain(function() { var layout1 = new
39 qx.ui.layout.VerticalBoxLayout(); layout1.setTop(40); layout1.setLeft(20);
40 layout1.setSpacing(4);
42 layout1.add(new qx.ui.basic.Label("URL:"));
43 var defaultURL = qx.io.remote.Rpc.makeServerURL();
44 if (defaultURL == null) {
45 defaultURL = "/services/";
47 var url = new qx.ui.form.TextField(defaultURL);
48 layout1.add(url);
50 layout1.add(new qx.ui.basic.Label("Service path:"));
51 var service = new qx.ui.form.TextField("qooxdoo.test");
52 layout1.add(service);
54 var start = new qx.ui.form.Button("Start test");
55 layout1.add(start);
57 var rpc;
58 var mycall = null;
59 var test;
61 start.addEventListener("execute", function() {
62 try
64 var rpc = new qx.io.remote.Rpc(url.getValue(), service.getValue());
65 rpc.setTimeout(10000);
67 test = "getCurrentTimestamp";
68 layout1.warn("Calling '" + test + "'");
69 result = rpc.callSync(test);
70 layout1.warn("result: now=" + result.now);
71 layout1.warn("result: jsonDate=" + result.json.toString());
73 test = "getInteger";
74 layout1.warn("Calling '" + test + "'");
75 var result = rpc.callSync(test);
76 layout1.warn("result: {" + result + "}");
77 layout1.warn("Returns a number, got " + typeof(result) + ": " + (typeof(result) == "number" && isFinite(result) ? "true" : "false"));
79 test = "isInteger";
80 layout1.warn("Calling '" + test + "'");
81 result = rpc.callSync(test, 1);
82 layout1.warn("result: {" + result + "}");
83 layout1.warn("Returns an integer: " + result);
85 test = "getString";
86 layout1.warn("Calling '" + test + "'");
87 result = rpc.callSync(test);
88 layout1.warn("result: {" + result + "}");
89 layout1.warn("Returns a string: " + (typeof(result) == "string"));
91 test = "isString";
92 layout1.warn("Calling '" + test + "'");
93 result = rpc.callSync(test, "Hello World");
94 layout1.warn("result: {" + result + "}");
95 layout1.warn("Returns a string: " + result);
97 test = "getNull";
98 layout1.warn("Calling '" + test + "'");
99 var result = rpc.callSync(test);
100 layout1.warn("result: {" + result + "}");
101 layout1.warn("Returns null: " + (typeof(result) == "object" && result === null ? "true" : "false"));
103 test = "isNull";
104 layout1.warn("Calling '" + test + "'");
105 result = rpc.callSync(test, null);
106 layout1.warn("result: {" + result + "}");
107 layout1.warn("Returns null: " + result);
109 test = "getArrayInteger";
110 layout1.warn("Calling '" + test + "'");
111 result = rpc.callSync(test);
112 layout1.warn("result: {" + result + "}");
113 layout1.warn("Returns an array: " + ((typeof(result) == "object") && (result instanceof Array)));
115 test = "getArrayString";
116 layout1.warn("Calling '" + test + "'");
117 result = rpc.callSync(test);
118 layout1.warn("result: {" + result + "}");
119 layout1.warn("Returns an array: " + ((typeof(result) == "object") && (result instanceof Array)));
121 var dataArray = new Array(5);
123 for (i=0; i<5; i++)
125 dataArray[i] = i;
128 test = "isArray";
129 layout1.warn("Calling '" + test + "'");
130 result = rpc.callSync(test, dataArray);
131 layout1.warn("result: {" + result + "}");
133 dataArray = new Array(5);
135 for (i=0; i<5; i++)
137 dataArray[i] = "Element " + i;
140 test = "isArray";
141 layout1.warn("Calling '" + test + "'");
142 result = rpc.callSync(test, dataArray);
143 layout1.warn("result: {" + result + "}");
145 test = "getFloat";
146 layout1.warn("Calling '" + test + "'");
147 result = rpc.callSync(test);
148 layout1.warn("result: {" + result + "}");
149 layout1.warn("Returns a float: " + (typeof(result) == "number"));
151 test = "getObject";
152 layout1.warn("Calling '" + test + "'");
153 result = rpc.callSync(test);
154 layout1.warn("result: {" + result + "}");
155 layout1.warn("Returns an object: " + (typeof(result) == "object"));
157 test = "isObject";
158 layout1.warn("Calling '" + test + "'");
159 obj = new Object();
160 obj.s = "Hi there.";
161 obj.n = 23;
162 obj.o = new Object();
163 obj.o.s = "This is a test.";
164 result = rpc.callSync(test, obj);
165 layout1.warn("result: {" + result.toString() + "}");
166 layout1.warn("Returns an object: " + result);
168 test = "getTrue";
169 layout1.warn("Calling '" + test + "'");
170 result = rpc.callSync(test);
171 layout1.warn("result: {" + result.toString() + "}");
172 layout1.warn("Returns a boolean = true: " + (typeof(result) == "boolean"));
174 test = "getFalse";
175 layout1.warn("Calling '" + test + "'");
176 result = rpc.callSync(test);
177 layout1.warn("result: {" + result.toString() + "}");
178 layout1.warn("Returns a boolean = false: " + (typeof(result) == "boolean"));
180 test = "isBoolean";
181 layout1.warn("Calling '" + test + "'");
182 result = rpc.callSync(test, true);
183 layout1.warn("result: {" + result.toString() + "}");
184 layout1.warn("Returns a boolean: " + result);
186 test = "isBoolean";
187 layout1.warn("Calling '" + test + "'");
188 result = rpc.callSync(test, false);
189 layout1.warn("result: {" + result.toString() + "}");
190 layout1.warn("Returns a boolean: " + result);
192 Date.prototype.classname = "Date";
193 var date = new Date();
194 test = "getParam";
195 layout1.warn("Calling '" + test + "'");
196 result = rpc.callSync(test, date);
197 layout1.warn("result: {" + result + "}");
198 layout1.warn("Returns a date object, got " + (result.classname == date.classname));
199 layout1.warn("Returns matching time " + date.getTime() + " = " + result.getTime() + " :" + (result.getTime() == date.getTime()));
201 dataArray = new Array();
202 dataArray[0] = true;
203 dataArray[1] = false;
204 dataArray[2] = 1;
205 dataArray[3] = 1.1;
206 dataArray[4] = "Hello World";
207 dataArray[5] = new Array(5);
208 dataArray[6] = new Object();
209 dataArray[7] = new Date();
211 test = "getParams";
212 layout1.warn("Calling '" + test + "'");
213 result = rpc.callSync(test, dataArray[0], dataArray[1], dataArray[2], dataArray[3], dataArray[4], dataArray[5], dataArray[6], dataArray[7]);
214 layout1.warn("result: {" + result + "}");
216 for (i=0; i< dataArray.length; i++)
218 layout1.warn("Returned parameter (" + i + ") value '" + result[i] + "' matches '" + dataArray[i] + "': " + (result[i].toString() == dataArray[i].toString()));
219 layout1.warn("Returned parameter (" + i + ") type '" + typeof(result[i]) + "' matches '" + typeof(dataArray[i]) + "': " + (typeof(result[i]) == typeof(dataArray[i])));
222 test = "getError";
223 layout1.warn("Calling '" + test + "'");
224 result = rpc.callSync(test);
225 // should never get here; we should receive an exception
226 layout1.warn("ERROR: Should have received an exception! Got: " + result);
229 catch (ex)
231 alert("Exception on test " + test + ": " + ex);
235 var d = qx.ui.core.ClientDocument.getInstance();
236 d.add(layout1);
238 </script>
239 </body>
240 </html>