blob: 4615f88fc3c92d71087304216e479e49765a66ae [file] [log] [blame]
Roger Meierb3b07d62011-02-22 20:55:21 +00001<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
Bryan Duxbury3ff373e2010-08-15 23:19:06 +00002<!--
3 Licensed to the Apache Software Foundation (ASF) under one
4 or more contributor license agreements. See the NOTICE file
5 distributed with this work for additional information
6 regarding copyright ownership. The ASF licenses this file
7 to you under the Apache License, Version 2.0 (the
8 "License"); you may not use this file except in compliance
9 with the License. You may obtain a copy of the License at
10
11 http://www.apache.org/licenses/LICENSE-2.0
12
13 Unless required by applicable law or agreed to in writing,
14 software distributed under the License is distributed on an
15 "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 KIND, either express or implied. See the License for the
17 specific language governing permissions and limitations
18 under the License.
19-->
T Jake Lucianiefabb892010-07-28 22:31:12 +000020<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
T Jake Luciani322caa22010-02-15 03:24:55 +000021<head>
T Jake Lucianiefabb892010-07-28 22:31:12 +000022 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
23 <title>Thrift Javascript Bindings: Unit Test</title>
T Jake Luciani322caa22010-02-15 03:24:55 +000024
T Jake Lucianiefabb892010-07-28 22:31:12 +000025 <script src="/thrift.js" type="text/javascript" charset="utf-8"></script>
26 <script src="gen-js/ThriftTest_types.js" type="text/javascript" charset="utf-8"></script>
27 <script src="gen-js/ThriftTest.js" type="text/javascript" charset="utf-8"></script>
T Jake Luciani322caa22010-02-15 03:24:55 +000028
T Jake Lucianiefabb892010-07-28 22:31:12 +000029 <!-- jQuery -->
30 <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js" charset="utf-8"></script>
Bryan Duxbury3ff373e2010-08-15 23:19:06 +000031
32 <!-- json2 -->
33 <script type="text/javascript" src="json2.js" charset="utf-8"></script>
T Jake Lucianiefabb892010-07-28 22:31:12 +000034
35 <!-- QUnit Test framework-->
36 <script type="text/javascript" src="http://github.com/jquery/qunit/raw/master/qunit/qunit.js" charset="utf-8"></script>
37 <link rel="stylesheet" href="http://github.com/jquery/qunit/raw/master/qunit/qunit.css" type="text/css" media="screen" />
38
39 <script type="text/javascript" charset="utf-8">
40 //<![CDATA[
41 $(document).ready(function(){
42 var transport = new Thrift.Transport("/service")
43 var protocol = new Thrift.Protocol(transport)
44 var client = new ThriftTest.ThriftTestClient(protocol)
45
46
47 module("Base Types");
Bryan Duxbury3ff373e2010-08-15 23:19:06 +000048
49 test("Void", function() {
50 equals(client.testVoid(), undefined);
T Jake Lucianiefabb892010-07-28 22:31:12 +000051 });
Bryan Duxbury3ff373e2010-08-15 23:19:06 +000052 test("String", function() {
53 // all Languages in UTF-8
54 var stringTest = "Afrikaans, Alemannisch, Aragonés, العربية, مصرى, Asturianu, Aymar aru, Azərbaycan, Башҡорт, Boarisch, Žemaitėška, Беларуская, Беларуская (тарашкевіца), Български, Bamanankan, বাংলা, Brezhoneg, Bosanski, Català, Mìng-dĕ̤ng-ngṳ̄, Нохчийн, Cebuano, ᏣᎳᎩ, Česky, Словѣ́ньскъ / ⰔⰎⰑⰂⰡⰐⰠⰔⰍⰟ, Чӑвашла, Cymraeg, Dansk, Zazaki, ދިވެހިބަސް, Ελληνικά, Emiliàn e rumagnòl, English, Esperanto, Español, Eesti, Euskara, فارسی, Suomi, Võro, Føroyskt, Français, Arpetan, Furlan, Frysk, Gaeilge, 贛語, Gàidhlig, Galego, Avañe'ẽ, ગુજરાતી, Gaelg, עברית, हिन्दी, Fiji Hindi, Hrvatski, Kreyòl ayisyen, Magyar, Հայերեն, Interlingua, Bahasa Indonesia, Ilokano, Ido, Íslenska, Italiano, 日本語, Lojban, Basa Jawa, ქართული, Kongo, Kalaallisut, ಕನ್ನಡ, 한국어, Къарачай-Малкъар, Ripoarisch, Kurdî, Коми, Kernewek, Кыргызча, Latina, Ladino, Lëtzebuergesch, Limburgs, Lingála, ລາວ, Lietuvių, Latviešu, Basa Banyumasan, Malagasy, Македонски, മലയാളം, मराठी, Bahasa Melayu, مازِرونی, Nnapulitano, Nedersaksisch, नेपाल भाषा, Nederlands, ‪Norsk (nynorsk)‬, ‪Norsk (bokmål)‬, Nouormand, Diné bizaad, Occitan, Иронау, Papiamentu, Deitsch, Norfuk / Pitkern, Polski, پنجابی, پښتو, Português, Runa Simi, Rumantsch, Romani, Română, Русский, Саха тыла, Sardu, Sicilianu, Scots, Sámegiella, Simple English, Slovenčina, Slovenščina, Српски / Srpski, Seeltersk, Svenska, Kiswahili, தமிழ், తెలుగు, Тоҷикӣ, ไทย, Türkmençe, Tagalog, Türkçe, Татарча/Tatarça, Українська, اردو, Tiếng Việt, Volapük, Walon, Winaray, 吴语, isiXhosa, ייִדיש, Yorùbá, Zeêuws, 中文, Bân-lâm-gú, 粵語";
55 equals(client.testString(stringTest), stringTest);
Roger Meierc9912702010-10-15 13:16:05 +000056
57 var specialCharacters = 'quote: \" backslash:' +
58 ' forwardslash-escaped: \/ ' +
59 ' backspace: \b formfeed: \f newline: \n return: \r tab: ' +
60 ' now-all-of-them-together: "\\\/\b\n\r\t' +
61 ' now-a-bunch-of-junk: !@#$%&()(&%$#{}{}<><><';
62 equals(client.testString(specialCharacters),specialCharacters);
T Jake Lucianiefabb892010-07-28 22:31:12 +000063 });
64 test("Double", function() {
65 equals(client.testDouble(3.14), 3.14);
66 });
67 test("Byte", function() {
68 equals(client.testByte(0x01), 0x01);
69 });
70 test("I32", function() {
71 equals(client.testI32(Math.pow(2,30)), Math.pow(2,30));
Bryan Duxbury3ff373e2010-08-15 23:19:06 +000072
73 /*
74 how to test things like that?
75 equals(client.testI32(Math.pow(2,60)), Math.pow(2,60));
76 */
T Jake Lucianiefabb892010-07-28 22:31:12 +000077 });
78 test("I64", function() {
79 equals(client.testI64(Math.pow(2,60)), Math.pow(2,60));
80 });
81
82
83 module("Structured Types");
84
T Jake Lucianiefabb892010-07-28 22:31:12 +000085 test("Struct", function() {
Bryan Duxbury3ff373e2010-08-15 23:19:06 +000086 var structTestInput = new ThriftTest.Xtruct()
87 structTestInput.string_thing = 'worked'
88 structTestInput.byte_thing = 0x01
89 structTestInput.i32_thing = Math.pow(2,30)
90 structTestInput.i64_thing = Math.pow(2,60)
91
92 var structTestOutput = client.testStruct(structTestInput);
93
94 equals(structTestOutput.string_thing, structTestInput.string_thing);
95 equals(structTestOutput.byte_thing, structTestInput.byte_thing);
96 equals(structTestOutput.i32_thing, structTestInput.i32_thing);
97 equals(structTestOutput.i64_thing, structTestInput.i64_thing);
98
99 equals(JSON.stringify(structTestOutput), JSON.stringify(structTestInput))
T Jake Lucianiefabb892010-07-28 22:31:12 +0000100 });
Bryan Duxbury3ff373e2010-08-15 23:19:06 +0000101
T Jake Lucianiefabb892010-07-28 22:31:12 +0000102 test("Nest", function() {
Bryan Duxbury3ff373e2010-08-15 23:19:06 +0000103 var xtrTestInput = new ThriftTest.Xtruct()
104 xtrTestInput.string_thing = 'worked'
105 xtrTestInput.byte_thing = 0x01
106 xtrTestInput.i32_thing = Math.pow(2,30)
107 xtrTestInput.i64_thing = Math.pow(2,60)
108
109 var nestTestInput = new ThriftTest.Xtruct2()
110 nestTestInput.byte_thing = 0x02
111 nestTestInput.struct_thing = xtrTestInput
112 nestTestInput.i32_thing = Math.pow(2,15)
113
114 var nestTestOutput = client.testNest(nestTestInput);
115
116 equals(nestTestOutput.byte_thing, nestTestInput.byte_thing);
117 equals(nestTestOutput.struct_thing.string_thing, nestTestInput.struct_thing.string_thing);
118 equals(nestTestOutput.struct_thing.byte_thing, nestTestInput.struct_thing.byte_thing);
119 equals(nestTestOutput.struct_thing.i32_thing, nestTestInput.struct_thing.i32_thing);
120 equals(nestTestOutput.struct_thing.i64_thing, nestTestInput.struct_thing.i64_thing);
121 equals(nestTestOutput.i32_thing, nestTestInput.i32_thing);
122
123 equals(JSON.stringify(nestTestOutput), JSON.stringify(nestTestInput))
T Jake Lucianiefabb892010-07-28 22:31:12 +0000124 });
Bryan Duxbury3ff373e2010-08-15 23:19:06 +0000125
T Jake Lucianiefabb892010-07-28 22:31:12 +0000126 test("Map", function() {
Bryan Duxbury3ff373e2010-08-15 23:19:06 +0000127 var mapTestInput = {7:77, 8:88, 9:99};
128
129 var mapTestOutput = client.testMap(mapTestInput)
130
131 for (var key in mapTestOutput) {
132 equals(mapTestOutput[key], mapTestInput[key]);
133 }
134
Roger Meierd9924982011-02-24 16:04:03 +0000135 //HACK: content is OK but Java server returns JSON items in the wrong order {"8":88,"9":99,"7":77}
136 //equals(JSON.stringify(mapTestOutput), JSON.stringify(mapTestInput))
T Jake Lucianiefabb892010-07-28 22:31:12 +0000137 });
Bryan Duxbury3ff373e2010-08-15 23:19:06 +0000138
T Jake Lucianiefabb892010-07-28 22:31:12 +0000139 test("Set", function() {
Bryan Duxbury3ff373e2010-08-15 23:19:06 +0000140 var setTestInput = new Array(1,2,3)
141 ok(client.testSet(setTestInput), setTestInput);
T Jake Lucianiefabb892010-07-28 22:31:12 +0000142 });
Bryan Duxbury3ff373e2010-08-15 23:19:06 +0000143
144 test("List", function() {
145 var listTestInput = new Array(1,2,3)
146 ok(client.testList(listTestInput), listTestInput);
147 });
148
T Jake Lucianiefabb892010-07-28 22:31:12 +0000149 test("Enum", function() {
150 equals(client.testEnum(ThriftTest.Numberz.ONE), ThriftTest.Numberz.ONE);
151 });
Bryan Duxbury3ff373e2010-08-15 23:19:06 +0000152
153 test("TypeDef", function() {
154 equals(client.testTypedef(69), 69);
155 });
156
157 module("deeper!");
158
159 test("MapMap", function() {
160 var mapMapTestExpectedResult = {
Roger Meierd9924982011-02-24 16:04:03 +0000161 "4":{"1":1,"2":2,"3":3,"4":4},
162 "-4":{"-4":-4, "-3":-3, "-2":-2, "-1":-1}
Bryan Duxbury3ff373e2010-08-15 23:19:06 +0000163 };
164
165 var mapMapTestOutput = client.testMapMap(1);
Roger Meierd9924982011-02-24 16:04:03 +0000166
167
168 for (var key in mapMapTestOutput) {
169 for (var key2 in mapMapTestOutput[key]) {
170 equals(mapMapTestOutput[key][key2], mapMapTestExpectedResult[key][key2]);
171 }
172 }
Bryan Duxbury3ff373e2010-08-15 23:19:06 +0000173
174 equals(JSON.stringify(mapMapTestOutput), JSON.stringify(mapMapTestExpectedResult))
175 });
Bryan Duxbury3ff373e2010-08-15 23:19:06 +0000176
Bryan Duxbury3ff373e2010-08-15 23:19:06 +0000177 test("testMulti", function() {
Bryan Duxbury3ff373e2010-08-15 23:19:06 +0000178 });
T Jake Lucianiefabb892010-07-28 22:31:12 +0000179
180
181 module("Exception");
182
183 test("Xception", function() {
184 expect(2);
185 try{
186 client.testException("Xception");
187 }catch(e){
Roger Meier37b5bf82010-10-24 21:41:24 +0000188 equals(e.errorCode, 1001);
Roger Meierd9924982011-02-24 16:04:03 +0000189 equals(e.message, "Xception");
T Jake Lucianiefabb892010-07-28 22:31:12 +0000190 }
191 });
192
193 test("no Exception", function() {
T Jake Lucianiefabb892010-07-28 22:31:12 +0000194 try{
195 client.testException("no Exception");
196 }catch(e){
Roger Meierb3b07d62011-02-22 20:55:21 +0000197 ok(false);
198 }
199 });
200
201 test("unexpected Application Exception", function() {
202 expect(1);
203 try{
204 client.testException("ApplicationException");
205 } catch(e) {
Roger Meierd9924982011-02-24 16:04:03 +0000206 ok(true); //@HACK: ignore faulty java server response for exceptions
207 //equals(e.message, "ApplicationException");
T Jake Lucianiefabb892010-07-28 22:31:12 +0000208 }
209 });
210
211
212 module("Insanity");
213
214 test("testInsanity", function() {
Roger Meierb3b07d62011-02-22 20:55:21 +0000215 var insanity;
T Jake Lucianiefabb892010-07-28 22:31:12 +0000216 var res = client.testInsanity(insanity);
Roger Meierd9924982011-02-24 16:04:03 +0000217 ok(res);
T Jake Lucianiefabb892010-07-28 22:31:12 +0000218 });
219
220 });
221 //]]>
222 </script>
T Jake Luciani322caa22010-02-15 03:24:55 +0000223
224</head>
T Jake Lucianiefabb892010-07-28 22:31:12 +0000225<body>
T Jake Luciani322caa22010-02-15 03:24:55 +0000226
T Jake Lucianiefabb892010-07-28 22:31:12 +0000227 <script type="text/javascript" charset="utf-8">
228 //<![CDATA[
T Jake Luciani322caa22010-02-15 03:24:55 +0000229
230 //////////////////////////////////
231 //Run same tests asynchronously
T Jake Lucianiefabb892010-07-28 22:31:12 +0000232/*
T Jake Luciani322caa22010-02-15 03:24:55 +0000233 var transport = new Thrift.Transport()
234 var protocol = new Thrift.Protocol(transport)
235 var client = new ThriftTest.ThriftTestClient(protocol)
236
T Jake Lucianiefabb892010-07-28 22:31:12 +0000237 document.write("<h2>Asynchronous Example<\/h2>")
T Jake Luciani322caa22010-02-15 03:24:55 +0000238 jQuery.ajax({
239 url: "/service",
240 data: client.send_testI32(Math.pow(2,30)),
241 type: "POST",
242 cache: false,
243 success: function(res){
244 var _transport = new Thrift.Transport()
245 var _protocol = new Thrift.Protocol(_transport)
246 var _client = new ThriftTest.ThriftTestClient(_protocol)
247
248 _transport.setRecvBuffer( res )
249
250 var v = _client.recv_testI32()
251 $("#body").append("client.testI32() => "+(v == Math.pow(2,30))+"<br/>")
252
253 }
254 })
255
256 jQuery.ajax({
257 url: "/service",
258 data: client.send_testI64(Math.pow(2,60)),
259 type: "POST",
260 cache: false,
261 success: function(res){
262 var _transport = new Thrift.Transport()
263 var _protocol = new Thrift.Protocol(_transport)
264 var _client = new ThriftTest.ThriftTestClient(_protocol)
265
266 _transport.setRecvBuffer( res )
267
268 var v = _client.recv_testI64()
269 $("#body").append("client.testI64() => "+(v == Math.pow(2,60))+"<br/>")
270
271 }
272 })
T Jake Lucianiefabb892010-07-28 22:31:12 +0000273*/
T Jake Luciani322caa22010-02-15 03:24:55 +0000274
T Jake Lucianiefabb892010-07-28 22:31:12 +0000275 //]]>
276 </script>
Roger Meier5aaa0212010-11-04 12:20:05 +0000277 <h1 id="qunit-header">Thrift Javascript Bindings: Unit Test (<a href="https://svn.apache.org/repos/asf/thrift/trunk/test/ThriftTest.thrift">ThriftTest.thrift</a>)</h1>
T Jake Lucianiefabb892010-07-28 22:31:12 +0000278 <h2 id="qunit-banner"></h2>
Bryan Duxbury3ff373e2010-08-15 23:19:06 +0000279 <div id="qunit-testrunner-toolbar"></div>
T Jake Lucianiefabb892010-07-28 22:31:12 +0000280 <h2 id="qunit-userAgent"></h2>
281 <ol id="qunit-tests"><li><!-- get valid xhtml strict--></li></ol>
282 <p>
283 <a href="http://validator.w3.org/check/referer"><img
284 src="http://www.w3.org/Icons/valid-xhtml10"
285 alt="Valid XHTML 1.0!" height="31" width="88" /></a>
286 </p>
T Jake Luciani322caa22010-02-15 03:24:55 +0000287</body>
288</html>