blob: f86dc37d33945d45141db73a20fb072ca2fb1c84 [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
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 });
Bryan Duxbury3ff373e2010-08-15 23:19:06 +0000168
Bryan Duxbury3ff373e2010-08-15 23:19:06 +0000169 test("testMulti", function() {
170 //var res = client.testInsanity(insanity);
171 //equals(res["1"]["1"].xtructs[0].string_thing, "worked");
172 });
T Jake Lucianiefabb892010-07-28 22:31:12 +0000173
174
175 module("Exception");
176
177 test("Xception", function() {
178 expect(2);
179 try{
180 client.testException("Xception");
181 }catch(e){
Roger Meier37b5bf82010-10-24 21:41:24 +0000182 equals(e.errorCode, 1001);
183 equals(e.message, "This is an Xception");
T Jake Lucianiefabb892010-07-28 22:31:12 +0000184 }
185 });
186
187 test("no Exception", function() {
T Jake Lucianiefabb892010-07-28 22:31:12 +0000188 try{
189 client.testException("no Exception");
190 }catch(e){
Roger Meierb3b07d62011-02-22 20:55:21 +0000191 ok(false);
192 }
193 });
194
195 test("unexpected Application Exception", function() {
196 expect(1);
197 try{
198 client.testException("ApplicationException");
199 } catch(e) {
200 ok(true);
T Jake Lucianiefabb892010-07-28 22:31:12 +0000201 }
202 });
203
204
205 module("Insanity");
206
207 test("testInsanity", function() {
Roger Meierb3b07d62011-02-22 20:55:21 +0000208 var insanity;
T Jake Lucianiefabb892010-07-28 22:31:12 +0000209 var res = client.testInsanity(insanity);
Roger Meierb3b07d62011-02-22 20:55:21 +0000210 equals(res["1"]["2"].xtructs[0].string_thing, "Goodbye4");
T Jake Lucianiefabb892010-07-28 22:31:12 +0000211 });
212
213 });
214 //]]>
215 </script>
T Jake Luciani322caa22010-02-15 03:24:55 +0000216
217</head>
T Jake Lucianiefabb892010-07-28 22:31:12 +0000218<body>
T Jake Luciani322caa22010-02-15 03:24:55 +0000219
T Jake Lucianiefabb892010-07-28 22:31:12 +0000220 <script type="text/javascript" charset="utf-8">
221 //<![CDATA[
T Jake Luciani322caa22010-02-15 03:24:55 +0000222
223 //////////////////////////////////
224 //Run same tests asynchronously
T Jake Lucianiefabb892010-07-28 22:31:12 +0000225/*
T Jake Luciani322caa22010-02-15 03:24:55 +0000226 var transport = new Thrift.Transport()
227 var protocol = new Thrift.Protocol(transport)
228 var client = new ThriftTest.ThriftTestClient(protocol)
229
T Jake Lucianiefabb892010-07-28 22:31:12 +0000230 document.write("<h2>Asynchronous Example<\/h2>")
T Jake Luciani322caa22010-02-15 03:24:55 +0000231 jQuery.ajax({
232 url: "/service",
233 data: client.send_testI32(Math.pow(2,30)),
234 type: "POST",
235 cache: false,
236 success: function(res){
237 var _transport = new Thrift.Transport()
238 var _protocol = new Thrift.Protocol(_transport)
239 var _client = new ThriftTest.ThriftTestClient(_protocol)
240
241 _transport.setRecvBuffer( res )
242
243 var v = _client.recv_testI32()
244 $("#body").append("client.testI32() => "+(v == Math.pow(2,30))+"<br/>")
245
246 }
247 })
248
249 jQuery.ajax({
250 url: "/service",
251 data: client.send_testI64(Math.pow(2,60)),
252 type: "POST",
253 cache: false,
254 success: function(res){
255 var _transport = new Thrift.Transport()
256 var _protocol = new Thrift.Protocol(_transport)
257 var _client = new ThriftTest.ThriftTestClient(_protocol)
258
259 _transport.setRecvBuffer( res )
260
261 var v = _client.recv_testI64()
262 $("#body").append("client.testI64() => "+(v == Math.pow(2,60))+"<br/>")
263
264 }
265 })
T Jake Lucianiefabb892010-07-28 22:31:12 +0000266*/
T Jake Luciani322caa22010-02-15 03:24:55 +0000267
T Jake Lucianiefabb892010-07-28 22:31:12 +0000268 //]]>
269 </script>
Roger Meier5aaa0212010-11-04 12:20:05 +0000270 <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 +0000271 <h2 id="qunit-banner"></h2>
Bryan Duxbury3ff373e2010-08-15 23:19:06 +0000272 <div id="qunit-testrunner-toolbar"></div>
T Jake Lucianiefabb892010-07-28 22:31:12 +0000273 <h2 id="qunit-userAgent"></h2>
274 <ol id="qunit-tests"><li><!-- get valid xhtml strict--></li></ol>
275 <p>
276 <a href="http://validator.w3.org/check/referer"><img
277 src="http://www.w3.org/Icons/valid-xhtml10"
278 alt="Valid XHTML 1.0!" height="31" width="88" /></a>
279 </p>
T Jake Luciani322caa22010-02-15 03:24:55 +0000280</body>
281</html>