blob: c5f4326e6d4526d494fe15a7da844e3dc081af4b [file] [log] [blame]
T Jake Lucianiefabb892010-07-28 22:31:12 +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
135 equals(JSON.stringify(mapTestOutput), JSON.stringify(mapTestInput))
T Jake Lucianiefabb892010-07-28 22:31:12 +0000136 });
Bryan Duxbury3ff373e2010-08-15 23:19:06 +0000137
T Jake Lucianiefabb892010-07-28 22:31:12 +0000138 test("Set", function() {
Bryan Duxbury3ff373e2010-08-15 23:19:06 +0000139 var setTestInput = new Array(1,2,3)
140 ok(client.testSet(setTestInput), setTestInput);
T Jake Lucianiefabb892010-07-28 22:31:12 +0000141 });
Bryan Duxbury3ff373e2010-08-15 23:19:06 +0000142
143 test("List", function() {
144 var listTestInput = new Array(1,2,3)
145 ok(client.testList(listTestInput), listTestInput);
146 });
147
T Jake Lucianiefabb892010-07-28 22:31:12 +0000148 test("Enum", function() {
149 equals(client.testEnum(ThriftTest.Numberz.ONE), ThriftTest.Numberz.ONE);
150 });
Bryan Duxbury3ff373e2010-08-15 23:19:06 +0000151
152 test("TypeDef", function() {
153 equals(client.testTypedef(69), 69);
154 });
155
156 module("deeper!");
157
158 test("MapMap", function() {
159 var mapMapTestExpectedResult = {
160 "-4":{"-4":-4, "-3":-3, "-2":-2, "-1":-1},
161 "4":{"1":1,"2":2,"3":3,"4":4}
162 };
163
164 var mapMapTestOutput = client.testMapMap(1);
165
166 equals(JSON.stringify(mapMapTestOutput), JSON.stringify(mapMapTestExpectedResult))
167 });
168
169 test("testInsanity", function() {
170 var insanityTestOutput;
171 var insanityTestInput;
172
173 // map<UserId, map<Numberz,Insanity>> testInsanity(1: Insanity argument),
174
175 var insanity = new ThriftTest.Insanity()
176 insanity.userMap[ThriftTest.Numberz.ONE] = 1
177 insanity.userMap[ThriftTest.Numberz.TWO] = 2
178
179
180 insanityTestOutput = client.testInsanity(insanity);
181 equals(JSON.stringify(insanityTestOutput), JSON.stringify(insanityTestInput))
182 /*
183 request:
184 [1,"testInsanity",1,0,{"1":{"rec":{"1":{"map":["i32","i64",2,{"1":1,"2":2}]},"2":{"lst":["rec",0]}}}}]
185 response:
186 [1,"testInsanity",2,0,{"0":{"map":["i64","map",2,{"1":["i32","rec",2,{"2":{"1":{"map":["i32","i64",2,{"5":5,"8":8}]},"2":{"lst":["rec",2,{"1":{"str":"Goodbye4"},"4":{"i8":4},"9":{"i32":4},"11":{"i64":4}},{"1":{"str":"Hello2"},"4":{"i8":2},"9":{"i32":2},"11":{"i64":2}}]}},"3":{"1":{"map":["i32","i64",2,{"5":5,"8":8}]},"2":{"lst":["rec",2,{"1":{"str":"Goodbye4"},"4":{"i8":4},"9":{"i32":4},"11":{"i64":4}},{"1":{"str":"Hello2"},"4":{"i8":2},"9":{"i32":2},"11":{"i64":2}}]}}}],"2":["i32","rec",1,{"6":{"1":{"map":["i32","i64",0,{}]},"2":{"lst":["rec",0]}}}]}]}}]
187 */
188 //equals(res["1"]["1"].xtructs[0].string_thing, "worked");
189 });
190 test("testMulti", function() {
191 //var res = client.testInsanity(insanity);
192 //equals(res["1"]["1"].xtructs[0].string_thing, "worked");
193 });
T Jake Lucianiefabb892010-07-28 22:31:12 +0000194
195
196 module("Exception");
197
198 test("Xception", function() {
199 expect(2);
200 try{
201 client.testException("Xception");
202 }catch(e){
Roger Meier37b5bf82010-10-24 21:41:24 +0000203 equals(e.errorCode, 1001);
204 equals(e.message, "This is an Xception");
T Jake Lucianiefabb892010-07-28 22:31:12 +0000205 }
206 });
207
208 test("no Exception", function() {
209 expect(1);
210 try{
211 client.testException("no Exception");
212 }catch(e){
213 equals(e.message, "no Exception");
214 }
215 });
216
217
218 module("Insanity");
219
220 test("testInsanity", function() {
221 var res = client.testInsanity(insanity);
222 equals(res["1"]["1"].xtructs[0].string_thing, "worked");
223 });
224
225 });
226 //]]>
227 </script>
T Jake Luciani322caa22010-02-15 03:24:55 +0000228
229</head>
T Jake Lucianiefabb892010-07-28 22:31:12 +0000230<body>
T Jake Luciani322caa22010-02-15 03:24:55 +0000231
T Jake Lucianiefabb892010-07-28 22:31:12 +0000232 <script type="text/javascript" charset="utf-8">
233 //<![CDATA[
T Jake Luciani322caa22010-02-15 03:24:55 +0000234
235 //////////////////////////////////
236 //Run same tests asynchronously
T Jake Lucianiefabb892010-07-28 22:31:12 +0000237/*
T Jake Luciani322caa22010-02-15 03:24:55 +0000238 var transport = new Thrift.Transport()
239 var protocol = new Thrift.Protocol(transport)
240 var client = new ThriftTest.ThriftTestClient(protocol)
241
T Jake Lucianiefabb892010-07-28 22:31:12 +0000242 document.write("<h2>Asynchronous Example<\/h2>")
T Jake Luciani322caa22010-02-15 03:24:55 +0000243 jQuery.ajax({
244 url: "/service",
245 data: client.send_testI32(Math.pow(2,30)),
246 type: "POST",
247 cache: false,
248 success: function(res){
249 var _transport = new Thrift.Transport()
250 var _protocol = new Thrift.Protocol(_transport)
251 var _client = new ThriftTest.ThriftTestClient(_protocol)
252
253 _transport.setRecvBuffer( res )
254
255 var v = _client.recv_testI32()
256 $("#body").append("client.testI32() => "+(v == Math.pow(2,30))+"<br/>")
257
258 }
259 })
260
261 jQuery.ajax({
262 url: "/service",
263 data: client.send_testI64(Math.pow(2,60)),
264 type: "POST",
265 cache: false,
266 success: function(res){
267 var _transport = new Thrift.Transport()
268 var _protocol = new Thrift.Protocol(_transport)
269 var _client = new ThriftTest.ThriftTestClient(_protocol)
270
271 _transport.setRecvBuffer( res )
272
273 var v = _client.recv_testI64()
274 $("#body").append("client.testI64() => "+(v == Math.pow(2,60))+"<br/>")
275
276 }
277 })
T Jake Lucianiefabb892010-07-28 22:31:12 +0000278*/
T Jake Luciani322caa22010-02-15 03:24:55 +0000279
T Jake Lucianiefabb892010-07-28 22:31:12 +0000280 //]]>
281 </script>
282 <h1 id="qunit-header">Thrift Javascript Bindings: Unit Test (<a href="https://svn.apache.org/repos/asf/incubator/thrift/trunk/test/ThriftTest.thrift">ThriftTest.thrift</a>)</h1>
283 <h2 id="qunit-banner"></h2>
Bryan Duxbury3ff373e2010-08-15 23:19:06 +0000284 <div id="qunit-testrunner-toolbar"></div>
T Jake Lucianiefabb892010-07-28 22:31:12 +0000285 <h2 id="qunit-userAgent"></h2>
286 <ol id="qunit-tests"><li><!-- get valid xhtml strict--></li></ol>
287 <p>
288 <a href="http://validator.w3.org/check/referer"><img
289 src="http://www.w3.org/Icons/valid-xhtml10"
290 alt="Valid XHTML 1.0!" height="31" width="88" /></a>
291 </p>
T Jake Luciani322caa22010-02-15 03:24:55 +0000292</body>
293</html>