r19141: add a reasonable subset of the qooxdoo runtime environment, and example appli...
[Samba/ekacnet.git] / swat / apps / qooxdoo-examples / test / RPC_4.html
blob52a6f4674e753bc0f069bf7f53eddd6cd86f045c
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 asynchronous interface. This is the
28 interface that your applications should use. See the warning in
29 RPC_3.html regarding use of the synchronous interface.
30 </p>
31 </div>
33 <script type="text/javascript">
34 // qx.Settings.setCustomOfClass("qx.io.remote.RemoteExchange", "enableDebug", true);
35 qx.Settings.setCustomOfClass("qx.io.Json", "enableDebug", true);
37 qx.core.Init.getInstance().defineMain(function() {
38 var layout1 = new qx.ui.layout.VerticalBoxLayout();
39 layout1.setTop(40);
40 layout1.setLeft(20);
41 layout1.setSpacing(4);
43 var crossDomain = new qx.ui.form.CheckBox("Cross Domain");
44 layout1.add(crossDomain);
46 layout1.add(new qx.ui.basic.Label("URL:"));
47 var defaultURL = qx.io.remote.Rpc.makeServerURL();
48 if (defaultURL == null) {
49 defaultURL = "/services/";
51 var url = new qx.ui.form.TextField(defaultURL);
52 layout1.add(url);
54 layout1.add(new qx.ui.basic.Label("Service path:"));
55 var service = new qx.ui.form.TextField("qooxdoo.test");
56 layout1.add(service);
58 var start = new qx.ui.form.Button("Start test");
59 layout1.add(start);
61 var mycall = null;
62 var test;
63 var testNum;
65 start.addEventListener("execute", function() {
66 var obj;
67 var date;
68 var dataArray;
71 * Create an array of each of the tests. Each array element is itself
72 * an array of two function: the first to issue the test request, and
73 * the second to validate the result.
75 var tests =
78 function()
80 test = "getCurrentTimestamp";
81 layout1.warn("Calling '" + test + "'");
82 mycall = rpc.callAsync(handler, test);
85 function(result)
87 layout1.warn("result: now=" + result.now);
88 layout1.warn("result: jsonDate=" + result.json.toString());
93 function()
95 test = "getInteger";
96 layout1.warn("Calling '" + test + "'");
97 mycall = rpc.callAsync(handler, test);
100 function(result)
102 layout1.warn("result: {" + result + "}");
103 layout1.warn("Returns a number, got " + typeof(result) + ": " + (typeof(result) == "number" && isFinite(result) ? "true" : "false"));
108 function()
110 test = "isInteger";
111 layout1.warn("Calling '" + test + "'");
112 mycall = rpc.callAsync(handler, test, 1);
115 function(result)
117 layout1.warn("result: {" + result + "}");
118 layout1.warn("Returns an integer: " + result);
123 function()
125 test = "getString";
126 layout1.warn("Calling '" + test + "'");
127 mycall = rpc.callAsync(handler, test);
130 function(result)
132 layout1.warn("result: {" + result + "}");
133 layout1.warn("Returns a string: " + (typeof(result) == "string"));
138 function()
140 test = "isString";
141 layout1.warn("Calling '" + test + "'");
142 mycall = rpc.callAsync(handler, test, "Hello World");
145 function(result)
147 layout1.warn("result: {" + result + "}");
148 layout1.warn("Returns a string: " + result);
153 function()
155 test = "getNull";
156 layout1.warn("Calling '" + test + "'");
157 var mycall = rpc.callAsync(handler, test);
160 function(result)
162 layout1.warn("result: {" + result + "}");
163 layout1.warn("Returns null: " + (typeof(result) == "object" && mycall === null ? "true" : "false"));
168 function()
170 test = "isNull";
171 layout1.warn("Calling '" + test + "'");
172 mycall = rpc.callAsync(handler, test, null);
175 function(result)
177 layout1.warn("result: {" + result + "}");
178 layout1.warn("Returns null: " + result);
183 function()
185 test = "getArrayInteger";
186 layout1.warn("Calling '" + test + "'");
187 mycall = rpc.callAsync(handler, test);
190 function(result)
192 layout1.warn("result: {" + result + "}");
193 layout1.warn("Returns an array: " + ((typeof(result) == "object") && (result instanceof Array)));
198 function()
200 test = "getArrayString";
201 layout1.warn("Calling '" + test + "'");
202 mycall = rpc.callAsync(handler, test);
205 function(result)
207 layout1.warn("result: {" + result + "}");
208 layout1.warn("Returns an array: " + ((typeof(result) == "object") && (result instanceof Array)));
213 function()
215 dataArray = new Array(5);
217 for (i=0; i<5; i++)
219 dataArray[i] = i;
222 test = "isArray";
223 layout1.warn("Calling '" + test + "'");
224 mycall = rpc.callAsync(handler, test, dataArray);
227 function(result)
229 layout1.warn("result: {" + result + "}");
230 layout1.warn("Returns an array: " + result);
235 function()
237 dataArray = new Array(5);
239 for (i=0; i<5; i++)
241 dataArray[i] = "Element " + i;
244 test = "isArray";
245 layout1.warn("Calling '" + test + "'");
246 mycall = rpc.callAsync(handler, test, dataArray);
249 function(result)
251 layout1.warn("result: {" + result + "}");
252 layout1.warn("Returns an array: " + result);
257 function()
259 test = "getFloat";
260 layout1.warn("Calling '" + test + "'");
261 mycall = rpc.callAsync(handler, test);
264 function(result)
266 layout1.warn("result: {" + result + "}");
267 layout1.warn("Returns a float: " + (typeof(result) == "number"));
272 function()
274 test = "getObject";
275 layout1.warn("Calling '" + test + "'");
276 mycall = rpc.callAsync(handler, test);
279 function(result)
281 layout1.warn("result: {" + result + "}");
282 layout1.warn("Returns an object: " + (typeof(result) == "object"));
287 function()
289 test = "isObject";
290 layout1.warn("Calling '" + test + "'");
291 obj = new Object();
292 obj.s = "Hi there.";
293 obj.n = 23;
294 obj.o = new Object();
295 obj.o.s = "This is a test.";
296 mycall = rpc.callAsync(handler, test, obj);
299 function(result)
301 layout1.warn("result: {" + result.toString() + "}");
302 layout1.warn("Returns an object: " + result);
307 function()
309 test = "isBoolean";
310 layout1.warn("Calling '" + test + "'");
311 mycall = rpc.callAsync(handler, test, false);
314 function(result)
316 layout1.warn("result: {" + result.toString() + "}");
317 layout1.warn("Returns a boolean: " + result);
322 function()
324 test = "isBoolean";
325 layout1.warn("Calling '" + test + "'");
326 mycall = rpc.callAsync(handler, test, true);
329 function(result)
331 layout1.warn("result: {" + result.toString() + "}");
332 layout1.warn("Returns a boolean: " + result);
337 function()
339 test = "getTrue";
340 layout1.warn("Calling '" + test + "'");
341 mycall = rpc.callAsync(handler, test);
344 function(result)
346 layout1.warn("result: {" + result.toString() + "}");
347 layout1.warn("Returns a boolean = true: " + (typeof(result) == "boolean"));
352 function()
354 test = "getFalse";
355 layout1.warn("Calling '" + test + "'");
356 mycall = rpc.callAsync(handler, test);
359 function(result)
361 layout1.warn("result: {" + result.toString() + "}");
362 layout1.warn("Returns a boolean = false: " + (typeof(result) == "boolean"));
367 function()
369 Date.prototype.classname = "Date";
370 date = new Date();
371 test = "getParam";
372 layout1.warn("Calling '" + test + "'");
373 mycall = rpc.callAsync(handler, test, date);
376 function(result)
378 layout1.warn("result: {" + result + "}");
379 layout1.warn("Returns a date object, got " + (result.classname == date.classname));
380 layout1.warn("Returns matching time " + date.getTime() + " = " + result.getTime() + " :" + (result.getTime() == date.getTime()));
385 function()
387 dataArray = new Array();
388 dataArray[0] = true;
389 dataArray[1] = false;
390 dataArray[2] = 1;
391 dataArray[3] = 1.1;
392 dataArray[4] = "Hello World";
393 dataArray[5] = new Array(5);
394 dataArray[6] = new Object();
395 dataArray[7] = new Date();
397 test = "getParams";
398 layout1.warn("Calling '" + test + "'");
399 mycall = rpc.callAsync(handler, test, dataArray[0], dataArray[1], dataArray[2], dataArray[3], dataArray[4], dataArray[5], dataArray[6], dataArray[7]);
402 function(result)
404 layout1.warn("result: {" + result + "}");
406 for (i=0; i< dataArray.length; i++)
408 layout1.warn("Returned parameter (" + i + ") value '" + result[i] + "' matches '" + dataArray[i] + "': " + (result[i].toString() == dataArray[i].toString()));
409 layout1.warn("Returned parameter (" + i + ") type '" + typeof(result[i]) + "' matches '" + typeof(dataArray[i]) + "': " + (typeof(result[i]) == typeof(dataArray[i])));
415 function()
417 test = "getError";
418 layout1.warn("Calling '" + test + "'");
419 mycall = rpc.callAsync(handler, test);
422 function(result)
424 // should never get here; we should receive an exception
425 layout1.warn("ERROR: Should have received an exception! Got: " + result);
431 * This is the generic handler, used by each of the tests. It
432 * ascertains whether an exception occured and alert()s with the
433 * exception if so; otherwise it calls the result validation function
434 * and then starts the next test.
436 handler = function(result, ex, id) {
437 mycall = null;
438 if (ex !== null) {
439 alert("Async(" + id + ") exception: " + ex);
440 } else {
441 // display results of the completed test
442 tests[testNum][1](result); // [][1] = validate response
444 // start the next test
445 ++testNum;
447 // Are we done?
448 if (testNum < tests.length) {
449 // Nope. Run the next test.
450 tests[testNum][0]();
455 // Determine which transport to use
456 rpc = new qx.io.remote.Rpc(url.getValue(), service.getValue());
457 rpc.setTimeout(10000);
458 rpc.setCrossDomain(crossDomain.isChecked());
460 // start the first test
461 testNum = 0;
462 tests[testNum][0](); // [][0] = request
465 var d = qx.ui.core.ClientDocument.getInstance();
466 d.add(layout1);
468 </script>
469 </body>
470 </html>