blob: e3b8d51d6d0e91c7a2d299af983a5a0f74b17004 [file] [log] [blame]
henriquea2de4102014-02-07 14:12:56 +01001/*
Roger Meierbb267d42011-07-30 15:10:42 +00002 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied. See the License for the
16 * specific language governing permissions and limitations
17 * under the License.
18 */
Henrique Mendonça095ddb72013-09-20 19:38:03 +020019 /* jshint -W100 */
Roger Meier08562732015-06-14 22:30:22 +020020
Roger Meierbb267d42011-07-30 15:10:42 +000021/*
henriquea2de4102014-02-07 14:12:56 +010022 * JavaScript test suite for ThriftTest.thrift. These tests
23 * will run against Normal (-gen js) and jQuery (-gen js:jquery)
24 * Apache Thrift interfaces.
25 *
Kazuki Matsudab909a382016-02-13 19:36:09 +090026 * Synchronous blocking calls should be identical in both
henriquea2de4102014-02-07 14:12:56 +010027 * Normal and jQuery interfaces. All synchronous tests belong
28 * here.
Roger Meier08562732015-06-14 22:30:22 +020029 *
30 * Asynchronous success callbacks passed as the last parameter
henriquea2de4102014-02-07 14:12:56 +010031 * of an RPC call should be identical in both Normal and jQuery
32 * interfaces. Async success tests belong here.
Roger Meier08562732015-06-14 22:30:22 +020033 *
henriquea2de4102014-02-07 14:12:56 +010034 * Asynchronous exception processing is different in Normal
35 * and jQuery interfaces. Such tests belong in the test-nojq.js
36 * or test-jq.js files respectively. jQuery specific XHR object
Roger Meier08562732015-06-14 22:30:22 +020037 * tests also belong in test-jq.js. Do not create any jQuery
henriquea2de4102014-02-07 14:12:56 +010038 * dependencies in this file or in test-nojq.js
39 *
40 * To compile client code for this test use:
41 * $ thrift -gen js ThriftTest.thrift
42 * -- or --
43 * $ thrift -gen js:jquery ThriftTest.thrift
44 *
45 * See also:
Roger Meier08562732015-06-14 22:30:22 +020046 * ++ test-nojq.js for "-gen js" only tests
henriquea2de4102014-02-07 14:12:56 +010047 * ++ test-jq.js for "-gen js:jquery" only tests
Roger Meierbb267d42011-07-30 15:10:42 +000048 */
49
Kazuki Matsudab909a382016-02-13 19:36:09 +090050var transport = new Thrift.Transport('/service');
51var protocol = new Thrift.Protocol(transport);
52var client = new ThriftTest.ThriftTestClient(protocol);
Roger Meierbb267d42011-07-30 15:10:42 +000053
Nobuaki Sukegawa72f88092015-05-10 23:35:29 +090054// Work around for old API used by QUnitAdapter of jsTestDriver
55if (typeof QUnit.log == 'function') {
56 // When using real QUnit (fron PhantomJS) log failures to console
57 QUnit.log(function(details) {
58 if (!details.result) {
59 console.log('======== FAIL ========');
60 console.log('TestName: ' + details.name);
Nobuaki Sukegawa6defea52015-11-14 17:36:29 +090061 if (details.message) console.log(details.message);
Nobuaki Sukegawa72f88092015-05-10 23:35:29 +090062 console.log('Expected: ' + details.expected);
63 console.log('Actual : ' + details.actual);
64 console.log('======================');
65 }
66 });
67}
68
Roger Meierbb267d42011-07-30 15:10:42 +000069// all Languages in UTF-8
70var 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ú, 粵語";
Roger Meier08562732015-06-14 22:30:22 +020071
Roger Meier4f8a5232011-09-09 08:17:02 +000072function checkRecursively(map1, map2) {
73 if (typeof map1 !== 'function' && typeof map2 !== 'function') {
74 if (!map1 || typeof map1 !== 'object') {
Roger Meierb661e832012-04-15 15:58:43 +000075 equal(map1, map2);
Roger Meier4f8a5232011-09-09 08:17:02 +000076 } else {
77 for (var key in map1) {
78 checkRecursively(map1[key], map2[key]);
79 }
80 }
81 }
82}
Roger Meierbb267d42011-07-30 15:10:42 +000083
Kazuki Matsudab909a382016-02-13 19:36:09 +090084module('Base Types');
Roger Meierbb267d42011-07-30 15:10:42 +000085
Kazuki Matsudab909a382016-02-13 19:36:09 +090086 test('Void', function() {
Roger Meierb661e832012-04-15 15:58:43 +000087 equal(client.testVoid(), undefined);
Roger Meierbb267d42011-07-30 15:10:42 +000088 });
Kazuki Matsudab909a382016-02-13 19:36:09 +090089 test('Binary (String)', function() {
Nobuaki Sukegawa6defea52015-11-14 17:36:29 +090090 var binary = '';
91 for (var v = 255; v >= 0; --v) {
92 binary += String.fromCharCode(v);
93 }
94 equal(client.testBinary(binary), binary);
95 });
Kazuki Matsudab909a382016-02-13 19:36:09 +090096 test('Binary (Uint8Array)', function() {
Nobuaki Sukegawa6defea52015-11-14 17:36:29 +090097 var binary = '';
98 for (var v = 255; v >= 0; --v) {
99 binary += String.fromCharCode(v);
100 }
101 var arr = new Uint8Array(binary.length);
102 for (var i = 0; i < binary.length; ++i) {
103 arr[i] = binary[i].charCodeAt();
104 }
105 equal(client.testBinary(arr), binary);
106 });
Kazuki Matsudab909a382016-02-13 19:36:09 +0900107 test('String', function() {
Henrique Mendonca6af2ec02012-09-27 13:14:36 +0000108 equal(client.testString(''), '');
Roger Meierb661e832012-04-15 15:58:43 +0000109 equal(client.testString(stringTest), stringTest);
Roger Meierbb267d42011-07-30 15:10:42 +0000110
111 var specialCharacters = 'quote: \" backslash:' +
112 ' forwardslash-escaped: \/ ' +
113 ' backspace: \b formfeed: \f newline: \n return: \r tab: ' +
114 ' now-all-of-them-together: "\\\/\b\n\r\t' +
115 ' now-a-bunch-of-junk: !@#$%&()(&%$#{}{}<><><';
Kazuki Matsudab909a382016-02-13 19:36:09 +0900116 equal(client.testString(specialCharacters), specialCharacters);
Roger Meierbb267d42011-07-30 15:10:42 +0000117 });
Kazuki Matsudab909a382016-02-13 19:36:09 +0900118 test('Double', function() {
Henrique Mendonca6af2ec02012-09-27 13:14:36 +0000119 equal(client.testDouble(0), 0);
120 equal(client.testDouble(-1), -1);
Roger Meierb661e832012-04-15 15:58:43 +0000121 equal(client.testDouble(3.14), 3.14);
Kazuki Matsudab909a382016-02-13 19:36:09 +0900122 equal(client.testDouble(Math.pow(2, 60)), Math.pow(2, 60));
Roger Meierbb267d42011-07-30 15:10:42 +0000123 });
Kazuki Matsudab909a382016-02-13 19:36:09 +0900124 test('Byte', function() {
Henrique Mendonca6af2ec02012-09-27 13:14:36 +0000125 equal(client.testByte(0), 0);
Roger Meierb661e832012-04-15 15:58:43 +0000126 equal(client.testByte(0x01), 0x01);
Roger Meierbb267d42011-07-30 15:10:42 +0000127 });
Kazuki Matsudab909a382016-02-13 19:36:09 +0900128 test('I32', function() {
Henrique Mendonca6af2ec02012-09-27 13:14:36 +0000129 equal(client.testI32(0), 0);
Kazuki Matsudab909a382016-02-13 19:36:09 +0900130 equal(client.testI32(Math.pow(2, 30)), Math.pow(2, 30));
131 equal(client.testI32(-Math.pow(2, 30)), -Math.pow(2, 30));
Roger Meierbb267d42011-07-30 15:10:42 +0000132 });
Kazuki Matsudab909a382016-02-13 19:36:09 +0900133 test('I64', function() {
Henrique Mendonca6af2ec02012-09-27 13:14:36 +0000134 equal(client.testI64(0), 0);
henriquea2de4102014-02-07 14:12:56 +0100135 //This is usually 2^60 but JS cannot represent anything over 2^52 accurately
Kazuki Matsudab909a382016-02-13 19:36:09 +0900136 equal(client.testI64(Math.pow(2, 52)), Math.pow(2, 52));
137 equal(client.testI64(-Math.pow(2, 52)), -Math.pow(2, 52));
Roger Meierbb267d42011-07-30 15:10:42 +0000138 });
139
140
Kazuki Matsudab909a382016-02-13 19:36:09 +0900141module('Structured Types');
Roger Meierbb267d42011-07-30 15:10:42 +0000142
Kazuki Matsudab909a382016-02-13 19:36:09 +0900143 test('Struct', function() {
Roger Meieredf0d1d2011-08-03 21:21:43 +0000144 var structTestInput = new ThriftTest.Xtruct();
145 structTestInput.string_thing = 'worked';
146 structTestInput.byte_thing = 0x01;
Kazuki Matsudab909a382016-02-13 19:36:09 +0900147 structTestInput.i32_thing = Math.pow(2, 30);
henriquea2de4102014-02-07 14:12:56 +0100148 //This is usually 2^60 but JS cannot represent anything over 2^52 accurately
Kazuki Matsudab909a382016-02-13 19:36:09 +0900149 structTestInput.i64_thing = Math.pow(2, 52);
Roger Meierbb267d42011-07-30 15:10:42 +0000150
151 var structTestOutput = client.testStruct(structTestInput);
152
Roger Meierb661e832012-04-15 15:58:43 +0000153 equal(structTestOutput.string_thing, structTestInput.string_thing);
154 equal(structTestOutput.byte_thing, structTestInput.byte_thing);
155 equal(structTestOutput.i32_thing, structTestInput.i32_thing);
156 equal(structTestOutput.i64_thing, structTestInput.i64_thing);
Roger Meier08562732015-06-14 22:30:22 +0200157
Roger Meierb661e832012-04-15 15:58:43 +0000158 equal(JSON.stringify(structTestOutput), JSON.stringify(structTestInput));
Roger Meierbb267d42011-07-30 15:10:42 +0000159 });
160
Kazuki Matsudab909a382016-02-13 19:36:09 +0900161 test('Nest', function() {
Roger Meieredf0d1d2011-08-03 21:21:43 +0000162 var xtrTestInput = new ThriftTest.Xtruct();
163 xtrTestInput.string_thing = 'worked';
164 xtrTestInput.byte_thing = 0x01;
Kazuki Matsudab909a382016-02-13 19:36:09 +0900165 xtrTestInput.i32_thing = Math.pow(2, 30);
henriquea2de4102014-02-07 14:12:56 +0100166 //This is usually 2^60 but JS cannot represent anything over 2^52 accurately
Kazuki Matsudab909a382016-02-13 19:36:09 +0900167 xtrTestInput.i64_thing = Math.pow(2, 52);
Roger Meier08562732015-06-14 22:30:22 +0200168
Roger Meieredf0d1d2011-08-03 21:21:43 +0000169 var nestTestInput = new ThriftTest.Xtruct2();
170 nestTestInput.byte_thing = 0x02;
171 nestTestInput.struct_thing = xtrTestInput;
Kazuki Matsudab909a382016-02-13 19:36:09 +0900172 nestTestInput.i32_thing = Math.pow(2, 15);
Roger Meier08562732015-06-14 22:30:22 +0200173
Roger Meierbb267d42011-07-30 15:10:42 +0000174 var nestTestOutput = client.testNest(nestTestInput);
Roger Meier08562732015-06-14 22:30:22 +0200175
Roger Meierb661e832012-04-15 15:58:43 +0000176 equal(nestTestOutput.byte_thing, nestTestInput.byte_thing);
177 equal(nestTestOutput.struct_thing.string_thing, nestTestInput.struct_thing.string_thing);
178 equal(nestTestOutput.struct_thing.byte_thing, nestTestInput.struct_thing.byte_thing);
179 equal(nestTestOutput.struct_thing.i32_thing, nestTestInput.struct_thing.i32_thing);
180 equal(nestTestOutput.struct_thing.i64_thing, nestTestInput.struct_thing.i64_thing);
181 equal(nestTestOutput.i32_thing, nestTestInput.i32_thing);
Roger Meier08562732015-06-14 22:30:22 +0200182
Roger Meierb661e832012-04-15 15:58:43 +0000183 equal(JSON.stringify(nestTestOutput), JSON.stringify(nestTestInput));
Roger Meierbb267d42011-07-30 15:10:42 +0000184 });
185
Kazuki Matsudab909a382016-02-13 19:36:09 +0900186 test('Map', function() {
187 var mapTestInput = {7: 77, 8: 88, 9: 99};
Roger Meierbb267d42011-07-30 15:10:42 +0000188
Roger Meieredf0d1d2011-08-03 21:21:43 +0000189 var mapTestOutput = client.testMap(mapTestInput);
Roger Meierbb267d42011-07-30 15:10:42 +0000190
191 for (var key in mapTestOutput) {
Roger Meierb661e832012-04-15 15:58:43 +0000192 equal(mapTestOutput[key], mapTestInput[key]);
Roger Meierbb267d42011-07-30 15:10:42 +0000193 }
194 });
195
Kazuki Matsudab909a382016-02-13 19:36:09 +0900196 test('StringMap', function() {
Roger Meierbb267d42011-07-30 15:10:42 +0000197 var mapTestInput = {
Kazuki Matsudab909a382016-02-13 19:36:09 +0900198 'a': '123', 'a b': 'with spaces ', 'same': 'same', '0': 'numeric key',
199 'longValue': stringTest, stringTest: 'long key'
Roger Meierbb267d42011-07-30 15:10:42 +0000200 };
201
Roger Meieredf0d1d2011-08-03 21:21:43 +0000202 var mapTestOutput = client.testStringMap(mapTestInput);
Roger Meierbb267d42011-07-30 15:10:42 +0000203
204 for (var key in mapTestOutput) {
Roger Meierb661e832012-04-15 15:58:43 +0000205 equal(mapTestOutput[key], mapTestInput[key]);
Roger Meierbb267d42011-07-30 15:10:42 +0000206 }
207 });
208
Kazuki Matsudab909a382016-02-13 19:36:09 +0900209 test('Set', function() {
210 var setTestInput = [1, 2, 3];
Roger Meierbb267d42011-07-30 15:10:42 +0000211 ok(client.testSet(setTestInput), setTestInput);
212 });
213
Kazuki Matsudab909a382016-02-13 19:36:09 +0900214 test('List', function() {
215 var listTestInput = [1, 2, 3];
Roger Meierbb267d42011-07-30 15:10:42 +0000216 ok(client.testList(listTestInput), listTestInput);
217 });
218
Kazuki Matsudab909a382016-02-13 19:36:09 +0900219 test('Enum', function() {
Roger Meierb661e832012-04-15 15:58:43 +0000220 equal(client.testEnum(ThriftTest.Numberz.ONE), ThriftTest.Numberz.ONE);
Roger Meierbb267d42011-07-30 15:10:42 +0000221 });
222
Kazuki Matsudab909a382016-02-13 19:36:09 +0900223 test('TypeDef', function() {
Roger Meierb661e832012-04-15 15:58:43 +0000224 equal(client.testTypedef(69), 69);
Roger Meierbb267d42011-07-30 15:10:42 +0000225 });
226
Kazuki Matsudab909a382016-02-13 19:36:09 +0900227 test('Skip', function() {
Jens Geyer329d59a2014-06-19 22:11:53 +0200228 var structTestInput = new ThriftTest.Xtruct();
229 var modifiedClient = new ThriftTest.ThriftTestClient(protocol);
230
231 modifiedClient.recv_testStruct = function() {
Kazuki Matsudab909a382016-02-13 19:36:09 +0900232 var input = modifiedClient.input;
Jens Geyer329d59a2014-06-19 22:11:53 +0200233 var xtruct3 = new ThriftTest.Xtruct3();
234
235 input.readMessageBegin();
236 input.readStructBegin();
237
Roger Meier08562732015-06-14 22:30:22 +0200238 // read Xtruct data with Xtruct3
Jens Geyer329d59a2014-06-19 22:11:53 +0200239 input.readFieldBegin();
240 xtruct3.read(input);
241 input.readFieldEnd();
242 // read Thrift.Type.STOP message
243 input.readFieldBegin();
244 input.readFieldEnd();
245
246 input.readStructEnd();
247 input.readMessageEnd();
248
249 return xtruct3;
250 };
251
252 structTestInput.string_thing = 'worked';
Kazuki Matsudab909a382016-02-13 19:36:09 +0900253 structTestInput.byte_thing = 0x01;
254 structTestInput.i32_thing = Math.pow(2, 30);
255 structTestInput.i64_thing = Math.pow(2, 52);
Jens Geyer329d59a2014-06-19 22:11:53 +0200256
257 var structTestOutput = modifiedClient.testStruct(structTestInput);
258
259 equal(structTestOutput instanceof ThriftTest.Xtruct3, true);
260 equal(structTestOutput.string_thing, structTestInput.string_thing);
261 equal(structTestOutput.changed, null);
262 equal(structTestOutput.i32_thing, structTestInput.i32_thing);
263 equal(structTestOutput.i64_thing, structTestInput.i64_thing);
264 });
265
Roger Meierbb267d42011-07-30 15:10:42 +0000266
Kazuki Matsudab909a382016-02-13 19:36:09 +0900267module('deeper!');
Roger Meierbb267d42011-07-30 15:10:42 +0000268
Kazuki Matsudab909a382016-02-13 19:36:09 +0900269 test('MapMap', function() {
Roger Meierbb267d42011-07-30 15:10:42 +0000270 var mapMapTestExpectedResult = {
Kazuki Matsudab909a382016-02-13 19:36:09 +0900271 '4': {'1': 1, '2': 2, '3': 3, '4': 4},
272 '-4': {'-4': -4, '-3': -3, '-2': -2, '-1': -1}
Roger Meierbb267d42011-07-30 15:10:42 +0000273 };
274
275 var mapMapTestOutput = client.testMapMap(1);
276
277
278 for (var key in mapMapTestOutput) {
279 for (var key2 in mapMapTestOutput[key]) {
Roger Meierb661e832012-04-15 15:58:43 +0000280 equal(mapMapTestOutput[key][key2], mapMapTestExpectedResult[key][key2]);
Roger Meierbb267d42011-07-30 15:10:42 +0000281 }
282 }
Roger Meier08562732015-06-14 22:30:22 +0200283
Roger Meier4f8a5232011-09-09 08:17:02 +0000284 checkRecursively(mapMapTestOutput, mapMapTestExpectedResult);
Roger Meierbb267d42011-07-30 15:10:42 +0000285 });
286
287
Kazuki Matsudab909a382016-02-13 19:36:09 +0900288module('Exception');
Roger Meierbb267d42011-07-30 15:10:42 +0000289
Kazuki Matsudab909a382016-02-13 19:36:09 +0900290 test('Xception', function() {
Roger Meierbb267d42011-07-30 15:10:42 +0000291 expect(2);
Kazuki Matsudab909a382016-02-13 19:36:09 +0900292 try {
293 client.testException('Xception');
294 }catch (e) {
Roger Meierb661e832012-04-15 15:58:43 +0000295 equal(e.errorCode, 1001);
Kazuki Matsudab909a382016-02-13 19:36:09 +0900296 equal(e.message, 'Xception');
Roger Meierbb267d42011-07-30 15:10:42 +0000297 }
298 });
299
Kazuki Matsudab909a382016-02-13 19:36:09 +0900300 test('no Exception', 0, function() {
301 try {
302 client.testException('no Exception');
303 }catch (e) {
Roger Meierbb267d42011-07-30 15:10:42 +0000304 ok(false);
305 }
306 });
307
Kazuki Matsudab909a382016-02-13 19:36:09 +0900308 test('TException', function() {
henriquea2de4102014-02-07 14:12:56 +0100309 //ThriftTest does not list TException as a legal exception so it will
Roger Meier08562732015-06-14 22:30:22 +0200310 // generate an exception on the server that does not propagate back to
henriquea2de4102014-02-07 14:12:56 +0100311 // the client. This test has been modified to equate to "no exception"
Roger Meierbb267d42011-07-30 15:10:42 +0000312 expect(1);
Kazuki Matsudab909a382016-02-13 19:36:09 +0900313 try {
314 client.testException('TException');
315 } catch (e) {
henriquea2de4102014-02-07 14:12:56 +0100316 //ok(false);
Roger Meierbb267d42011-07-30 15:10:42 +0000317 }
henriquea2de4102014-02-07 14:12:56 +0100318 ok(true);
Roger Meierbb267d42011-07-30 15:10:42 +0000319 });
320
321
Kazuki Matsudab909a382016-02-13 19:36:09 +0900322module('Insanity');
Roger Meierbb267d42011-07-30 15:10:42 +0000323
Nobuaki Sukegawa01ede042015-09-29 02:16:53 +0900324 var crazy = {
Kazuki Matsudab909a382016-02-13 19:36:09 +0900325 'userMap': { '5': 5, '8': 8 },
326 'xtructs': [{
327 'string_thing': 'Goodbye4',
328 'byte_thing': 4,
329 'i32_thing': 4,
330 'i64_thing': 4
Nobuaki Sukegawa01ede042015-09-29 02:16:53 +0900331 },
332 {
Kazuki Matsudab909a382016-02-13 19:36:09 +0900333 'string_thing': 'Hello2',
334 'byte_thing': 2,
335 'i32_thing': 2,
336 'i64_thing': 2
Nobuaki Sukegawa01ede042015-09-29 02:16:53 +0900337 }]
338 };
Kazuki Matsudab909a382016-02-13 19:36:09 +0900339 test('testInsanity', function() {
Roger Meierbb267d42011-07-30 15:10:42 +0000340 var insanity = {
Kazuki Matsudab909a382016-02-13 19:36:09 +0900341 '1': {
342 '2': crazy,
343 '3': crazy
Roger Meierbb267d42011-07-30 15:10:42 +0000344 },
Kazuki Matsudab909a382016-02-13 19:36:09 +0900345 '2': { '6': { 'userMap': null, 'xtructs': null } }
Roger Meierbb267d42011-07-30 15:10:42 +0000346 };
Nobuaki Sukegawa01ede042015-09-29 02:16:53 +0900347 var res = client.testInsanity(new ThriftTest.Insanity(crazy));
Roger Meierbb267d42011-07-30 15:10:42 +0000348 ok(res, JSON.stringify(res));
349 ok(insanity, JSON.stringify(insanity));
Roger Meier4f8a5232011-09-09 08:17:02 +0000350
351 checkRecursively(res, insanity);
Roger Meierbb267d42011-07-30 15:10:42 +0000352 });
353
354
355//////////////////////////////////
356//Run same tests asynchronously
Roger Meierbb267d42011-07-30 15:10:42 +0000357
Kazuki Matsudab909a382016-02-13 19:36:09 +0900358module('Async');
Roger Meierbb267d42011-07-30 15:10:42 +0000359
Kazuki Matsudab909a382016-02-13 19:36:09 +0900360 test('Double', function() {
361 expect(1);
Roger Meierbb267d42011-07-30 15:10:42 +0000362
363 QUnit.stop();
364 client.testDouble(3.14159265, function(result) {
Roger Meierb661e832012-04-15 15:58:43 +0000365 equal(result, 3.14159265);
Roger Meierbb267d42011-07-30 15:10:42 +0000366 QUnit.start();
367 });
368 });
369
Kazuki Matsudab909a382016-02-13 19:36:09 +0900370 test('Byte', function() {
371 expect(1);
Roger Meierbb267d42011-07-30 15:10:42 +0000372
373 QUnit.stop();
374 client.testByte(0x01, function(result) {
Roger Meierb661e832012-04-15 15:58:43 +0000375 equal(result, 0x01);
Roger Meierbb267d42011-07-30 15:10:42 +0000376 QUnit.start();
377 });
378 });
379
Kazuki Matsudab909a382016-02-13 19:36:09 +0900380 test('I32', function() {
381 expect(2);
Roger Meierbb267d42011-07-30 15:10:42 +0000382
383 QUnit.stop();
Kazuki Matsudab909a382016-02-13 19:36:09 +0900384 client.testI32(Math.pow(2, 30), function(result) {
385 equal(result, Math.pow(2, 30));
Roger Meierbb267d42011-07-30 15:10:42 +0000386 QUnit.start();
387 });
388
389 QUnit.stop();
Kazuki Matsudab909a382016-02-13 19:36:09 +0900390 client.testI32(Math.pow(-2, 31), function(result) {
391 equal(result, Math.pow(-2, 31));
Roger Meierbb267d42011-07-30 15:10:42 +0000392 QUnit.start();
393 });
394 });
395
Kazuki Matsudab909a382016-02-13 19:36:09 +0900396 test('I64', function() {
397 expect(2);
Roger Meierbb267d42011-07-30 15:10:42 +0000398
399 QUnit.stop();
henriquea2de4102014-02-07 14:12:56 +0100400 //This is usually 2^60 but JS cannot represent anything over 2^52 accurately
Kazuki Matsudab909a382016-02-13 19:36:09 +0900401 client.testI64(Math.pow(2, 52), function(result) {
402 equal(result, Math.pow(2, 52));
Roger Meierbb267d42011-07-30 15:10:42 +0000403 QUnit.start();
henriquea2de4102014-02-07 14:12:56 +0100404 });
405
406 QUnit.stop();
407 //This is usually 2^60 but JS cannot represent anything over 2^52 accurately
Kazuki Matsudab909a382016-02-13 19:36:09 +0900408 client.testI64(Math.pow(-2, 52), function(result) {
409 equal(result, Math.pow(-2, 52));
henriquea2de4102014-02-07 14:12:56 +0100410 QUnit.start();
Roger Meierbb267d42011-07-30 15:10:42 +0000411 });
412 });