blob: 35ed6ffd28428bd4112d090f76191e7ff68ccee9 [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
Brian Forbisb5d6ea32018-08-25 23:39:29 -040050const transport = new Thrift.Transport('/service');
51const protocol = new Thrift.Protocol(transport);
52const client = new ThriftTest.ThriftTestClient(protocol);
Roger Meierbb267d42011-07-30 15:10:42 +000053
Mustafa Senol Cosarf86845e2018-12-05 17:50:18 +030054const int64_2_pow_60 = new Int64('1000000000000000');
55const int64_minus_2_pow_60 = new Int64('f000000000000000');
56
Nobuaki Sukegawa72f88092015-05-10 23:35:29 +090057// Work around for old API used by QUnitAdapter of jsTestDriver
58if (typeof QUnit.log == 'function') {
59 // When using real QUnit (fron PhantomJS) log failures to console
60 QUnit.log(function(details) {
61 if (!details.result) {
62 console.log('======== FAIL ========');
63 console.log('TestName: ' + details.name);
Nobuaki Sukegawa6defea52015-11-14 17:36:29 +090064 if (details.message) console.log(details.message);
Nobuaki Sukegawa72f88092015-05-10 23:35:29 +090065 console.log('Expected: ' + details.expected);
66 console.log('Actual : ' + details.actual);
67 console.log('======================');
68 }
69 });
70}
71
Roger Meierbb267d42011-07-30 15:10:42 +000072// all Languages in UTF-8
Brian Forbisb5d6ea32018-08-25 23:39:29 -040073const 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 +020074
Brian Forbisb5d6ea32018-08-25 23:39:29 -040075function checkRecursively(assert, map1, map2) {
Roger Meier4f8a5232011-09-09 08:17:02 +000076 if (typeof map1 !== 'function' && typeof map2 !== 'function') {
77 if (!map1 || typeof map1 !== 'object') {
Brian Forbisb5d6ea32018-08-25 23:39:29 -040078 assert.equal(map1, map2);
Roger Meier4f8a5232011-09-09 08:17:02 +000079 } else {
Brian Forbisb5d6ea32018-08-25 23:39:29 -040080 for (let key in map1) {
81 checkRecursively(assert, map1[key], map2[key]);
Roger Meier4f8a5232011-09-09 08:17:02 +000082 }
83 }
84 }
85}
Roger Meierbb267d42011-07-30 15:10:42 +000086
Brian Forbisb5d6ea32018-08-25 23:39:29 -040087QUnit.module('Base Types');
Roger Meierbb267d42011-07-30 15:10:42 +000088
Brian Forbisb5d6ea32018-08-25 23:39:29 -040089 QUnit.test('Void', function(assert) {
90 assert.equal(client.testVoid(), undefined);
Roger Meierbb267d42011-07-30 15:10:42 +000091 });
Brian Forbisb5d6ea32018-08-25 23:39:29 -040092 QUnit.test('Binary (String)', function(assert) {
93 let binary = '';
94 for (let v = 255; v >= 0; --v) {
Nobuaki Sukegawa6defea52015-11-14 17:36:29 +090095 binary += String.fromCharCode(v);
96 }
Brian Forbisb5d6ea32018-08-25 23:39:29 -040097 assert.equal(client.testBinary(binary), binary);
Nobuaki Sukegawa6defea52015-11-14 17:36:29 +090098 });
Brian Forbisb5d6ea32018-08-25 23:39:29 -040099 QUnit.test('Binary (Uint8Array)', function(assert) {
100 let binary = '';
101 for (let v = 255; v >= 0; --v) {
Nobuaki Sukegawa6defea52015-11-14 17:36:29 +0900102 binary += String.fromCharCode(v);
103 }
Brian Forbisb5d6ea32018-08-25 23:39:29 -0400104 const arr = new Uint8Array(binary.length);
105 for (let i = 0; i < binary.length; ++i) {
Nobuaki Sukegawa6defea52015-11-14 17:36:29 +0900106 arr[i] = binary[i].charCodeAt();
107 }
Brian Forbisb5d6ea32018-08-25 23:39:29 -0400108 assert.equal(client.testBinary(arr), binary);
Nobuaki Sukegawa6defea52015-11-14 17:36:29 +0900109 });
Brian Forbisb5d6ea32018-08-25 23:39:29 -0400110 QUnit.test('String', function(assert) {
111 assert.equal(client.testString(''), '');
112 assert.equal(client.testString(stringTest), stringTest);
Roger Meierbb267d42011-07-30 15:10:42 +0000113
Brian Forbisb5d6ea32018-08-25 23:39:29 -0400114 const specialCharacters = 'quote: \" backslash:' +
Roger Meierbb267d42011-07-30 15:10:42 +0000115 ' forwardslash-escaped: \/ ' +
116 ' backspace: \b formfeed: \f newline: \n return: \r tab: ' +
117 ' now-all-of-them-together: "\\\/\b\n\r\t' +
118 ' now-a-bunch-of-junk: !@#$%&()(&%$#{}{}<><><';
Brian Forbisb5d6ea32018-08-25 23:39:29 -0400119 assert.equal(client.testString(specialCharacters), specialCharacters);
Roger Meierbb267d42011-07-30 15:10:42 +0000120 });
Brian Forbisb5d6ea32018-08-25 23:39:29 -0400121 QUnit.test('Double', function(assert) {
122 assert.equal(client.testDouble(0), 0);
123 assert.equal(client.testDouble(-1), -1);
124 assert.equal(client.testDouble(3.14), 3.14);
125 assert.equal(client.testDouble(Math.pow(2, 60)), Math.pow(2, 60));
Roger Meierbb267d42011-07-30 15:10:42 +0000126 });
Brian Forbisb5d6ea32018-08-25 23:39:29 -0400127 QUnit.test('Byte', function(assert) {
128 assert.equal(client.testByte(0), 0);
129 assert.equal(client.testByte(0x01), 0x01);
Roger Meierbb267d42011-07-30 15:10:42 +0000130 });
Brian Forbisb5d6ea32018-08-25 23:39:29 -0400131 QUnit.test('I32', function(assert) {
132 assert.equal(client.testI32(0), 0);
133 assert.equal(client.testI32(Math.pow(2, 30)), Math.pow(2, 30));
134 assert.equal(client.testI32(-Math.pow(2, 30)), -Math.pow(2, 30));
Roger Meierbb267d42011-07-30 15:10:42 +0000135 });
Brian Forbisb5d6ea32018-08-25 23:39:29 -0400136 QUnit.test('I64', function(assert) {
137 assert.equal(client.testI64(0), 0);
Mustafa Senol Cosarf86845e2018-12-05 17:50:18 +0300138
139 let int64_2_pow_60_result = client.testI64(int64_2_pow_60);
140 assert.ok(int64_2_pow_60.equals(int64_2_pow_60_result));
141
142 let int64_minus_2_pow_60_result = client.testI64(int64_minus_2_pow_60);
143 assert.ok(int64_minus_2_pow_60.equals(int64_minus_2_pow_60_result));
Roger Meierbb267d42011-07-30 15:10:42 +0000144 });
145
146
Brian Forbisb5d6ea32018-08-25 23:39:29 -0400147QUnit.module('Structured Types');
Roger Meierbb267d42011-07-30 15:10:42 +0000148
Brian Forbisb5d6ea32018-08-25 23:39:29 -0400149 QUnit.test('Struct', function(assert) {
150 const structTestInput = new ThriftTest.Xtruct();
Roger Meieredf0d1d2011-08-03 21:21:43 +0000151 structTestInput.string_thing = 'worked';
152 structTestInput.byte_thing = 0x01;
Kazuki Matsudab909a382016-02-13 19:36:09 +0900153 structTestInput.i32_thing = Math.pow(2, 30);
Mustafa Senol Cosarf86845e2018-12-05 17:50:18 +0300154 structTestInput.i64_thing = int64_2_pow_60;
Roger Meierbb267d42011-07-30 15:10:42 +0000155
Brian Forbisb5d6ea32018-08-25 23:39:29 -0400156 const structTestOutput = client.testStruct(structTestInput);
Roger Meierbb267d42011-07-30 15:10:42 +0000157
Brian Forbisb5d6ea32018-08-25 23:39:29 -0400158 assert.equal(structTestOutput.string_thing, structTestInput.string_thing);
159 assert.equal(structTestOutput.byte_thing, structTestInput.byte_thing);
160 assert.equal(structTestOutput.i32_thing, structTestInput.i32_thing);
Mustafa Senol Cosarf86845e2018-12-05 17:50:18 +0300161 assert.ok(structTestOutput.i64_thing.equals(structTestInput.i64_thing));
Roger Meier08562732015-06-14 22:30:22 +0200162
Brian Forbisb5d6ea32018-08-25 23:39:29 -0400163 assert.equal(JSON.stringify(structTestOutput), JSON.stringify(structTestInput));
Roger Meierbb267d42011-07-30 15:10:42 +0000164 });
165
Brian Forbisb5d6ea32018-08-25 23:39:29 -0400166 QUnit.test('Nest', function(assert) {
167 const xtrTestInput = new ThriftTest.Xtruct();
Roger Meieredf0d1d2011-08-03 21:21:43 +0000168 xtrTestInput.string_thing = 'worked';
169 xtrTestInput.byte_thing = 0x01;
Kazuki Matsudab909a382016-02-13 19:36:09 +0900170 xtrTestInput.i32_thing = Math.pow(2, 30);
Mustafa Senol Cosarf86845e2018-12-05 17:50:18 +0300171 xtrTestInput.i64_thing = int64_2_pow_60;
Roger Meier08562732015-06-14 22:30:22 +0200172
Brian Forbisb5d6ea32018-08-25 23:39:29 -0400173 const nestTestInput = new ThriftTest.Xtruct2();
Roger Meieredf0d1d2011-08-03 21:21:43 +0000174 nestTestInput.byte_thing = 0x02;
175 nestTestInput.struct_thing = xtrTestInput;
Kazuki Matsudab909a382016-02-13 19:36:09 +0900176 nestTestInput.i32_thing = Math.pow(2, 15);
Roger Meier08562732015-06-14 22:30:22 +0200177
Brian Forbisb5d6ea32018-08-25 23:39:29 -0400178 const nestTestOutput = client.testNest(nestTestInput);
Roger Meier08562732015-06-14 22:30:22 +0200179
Brian Forbisb5d6ea32018-08-25 23:39:29 -0400180 assert.equal(nestTestOutput.byte_thing, nestTestInput.byte_thing);
181 assert.equal(nestTestOutput.struct_thing.string_thing, nestTestInput.struct_thing.string_thing);
182 assert.equal(nestTestOutput.struct_thing.byte_thing, nestTestInput.struct_thing.byte_thing);
183 assert.equal(nestTestOutput.struct_thing.i32_thing, nestTestInput.struct_thing.i32_thing);
Mustafa Senol Cosarf86845e2018-12-05 17:50:18 +0300184 assert.ok(nestTestOutput.struct_thing.i64_thing.equals(nestTestInput.struct_thing.i64_thing));
Brian Forbisb5d6ea32018-08-25 23:39:29 -0400185 assert.equal(nestTestOutput.i32_thing, nestTestInput.i32_thing);
Roger Meier08562732015-06-14 22:30:22 +0200186
Brian Forbisb5d6ea32018-08-25 23:39:29 -0400187 assert.equal(JSON.stringify(nestTestOutput), JSON.stringify(nestTestInput));
Roger Meierbb267d42011-07-30 15:10:42 +0000188 });
189
Brian Forbisb5d6ea32018-08-25 23:39:29 -0400190 QUnit.test('Map', function(assert) {
191 const mapTestInput = {7: 77, 8: 88, 9: 99};
Roger Meierbb267d42011-07-30 15:10:42 +0000192
Brian Forbisb5d6ea32018-08-25 23:39:29 -0400193 const mapTestOutput = client.testMap(mapTestInput);
Roger Meierbb267d42011-07-30 15:10:42 +0000194
Brian Forbisb5d6ea32018-08-25 23:39:29 -0400195 for (let key in mapTestOutput) {
196 assert.equal(mapTestOutput[key], mapTestInput[key]);
Roger Meierbb267d42011-07-30 15:10:42 +0000197 }
198 });
199
Brian Forbisb5d6ea32018-08-25 23:39:29 -0400200 QUnit.test('StringMap', function(assert) {
201 const mapTestInput = {
Kazuki Matsudab909a382016-02-13 19:36:09 +0900202 'a': '123', 'a b': 'with spaces ', 'same': 'same', '0': 'numeric key',
203 'longValue': stringTest, stringTest: 'long key'
Roger Meierbb267d42011-07-30 15:10:42 +0000204 };
205
Brian Forbisb5d6ea32018-08-25 23:39:29 -0400206 const mapTestOutput = client.testStringMap(mapTestInput);
Roger Meierbb267d42011-07-30 15:10:42 +0000207
Brian Forbisb5d6ea32018-08-25 23:39:29 -0400208 for (let key in mapTestOutput) {
209 assert.equal(mapTestOutput[key], mapTestInput[key]);
Roger Meierbb267d42011-07-30 15:10:42 +0000210 }
211 });
212
Brian Forbisb5d6ea32018-08-25 23:39:29 -0400213 QUnit.test('Set', function(assert) {
214 const setTestInput = [1, 2, 3];
215 assert.ok(client.testSet(setTestInput), setTestInput);
Roger Meierbb267d42011-07-30 15:10:42 +0000216 });
217
Brian Forbisb5d6ea32018-08-25 23:39:29 -0400218 QUnit.test('List', function(assert) {
219 const listTestInput = [1, 2, 3];
220 assert.ok(client.testList(listTestInput), listTestInput);
Roger Meierbb267d42011-07-30 15:10:42 +0000221 });
222
Brian Forbisb5d6ea32018-08-25 23:39:29 -0400223 QUnit.test('Enum', function(assert) {
224 assert.equal(client.testEnum(ThriftTest.Numberz.ONE), ThriftTest.Numberz.ONE);
Roger Meierbb267d42011-07-30 15:10:42 +0000225 });
226
Brian Forbisb5d6ea32018-08-25 23:39:29 -0400227 QUnit.test('TypeDef', function(assert) {
228 assert.equal(client.testTypedef(69), 69);
Roger Meierbb267d42011-07-30 15:10:42 +0000229 });
230
Brian Forbisb5d6ea32018-08-25 23:39:29 -0400231 QUnit.test('Skip', function(assert) {
232 const structTestInput = new ThriftTest.Xtruct();
233 const modifiedClient = new ThriftTest.ThriftTestClient(protocol);
Jens Geyer329d59a2014-06-19 22:11:53 +0200234
235 modifiedClient.recv_testStruct = function() {
Brian Forbisb5d6ea32018-08-25 23:39:29 -0400236 const input = modifiedClient.input;
237 const xtruct3 = new ThriftTest.Xtruct3();
Jens Geyer329d59a2014-06-19 22:11:53 +0200238
239 input.readMessageBegin();
240 input.readStructBegin();
241
Roger Meier08562732015-06-14 22:30:22 +0200242 // read Xtruct data with Xtruct3
Jens Geyer329d59a2014-06-19 22:11:53 +0200243 input.readFieldBegin();
244 xtruct3.read(input);
245 input.readFieldEnd();
246 // read Thrift.Type.STOP message
247 input.readFieldBegin();
248 input.readFieldEnd();
249
250 input.readStructEnd();
251 input.readMessageEnd();
252
253 return xtruct3;
254 };
255
256 structTestInput.string_thing = 'worked';
Kazuki Matsudab909a382016-02-13 19:36:09 +0900257 structTestInput.byte_thing = 0x01;
258 structTestInput.i32_thing = Math.pow(2, 30);
Mustafa Senol Cosarf86845e2018-12-05 17:50:18 +0300259 structTestInput.i64_thing = int64_2_pow_60;
Jens Geyer329d59a2014-06-19 22:11:53 +0200260
Brian Forbisb5d6ea32018-08-25 23:39:29 -0400261 const structTestOutput = modifiedClient.testStruct(structTestInput);
Jens Geyer329d59a2014-06-19 22:11:53 +0200262
Brian Forbisb5d6ea32018-08-25 23:39:29 -0400263 assert.equal(structTestOutput instanceof ThriftTest.Xtruct3, true);
264 assert.equal(structTestOutput.string_thing, structTestInput.string_thing);
265 assert.equal(structTestOutput.changed, null);
266 assert.equal(structTestOutput.i32_thing, structTestInput.i32_thing);
Mustafa Senol Cosarf86845e2018-12-05 17:50:18 +0300267 assert.ok(structTestOutput.i64_thing.equals(structTestInput.i64_thing));
Jens Geyer329d59a2014-06-19 22:11:53 +0200268 });
269
Roger Meierbb267d42011-07-30 15:10:42 +0000270
Brian Forbisb5d6ea32018-08-25 23:39:29 -0400271QUnit.module('deeper!');
Roger Meierbb267d42011-07-30 15:10:42 +0000272
Brian Forbisb5d6ea32018-08-25 23:39:29 -0400273 QUnit.test('MapMap', function(assert) {
274 const mapMapTestExpectedResult = {
Kazuki Matsudab909a382016-02-13 19:36:09 +0900275 '4': {'1': 1, '2': 2, '3': 3, '4': 4},
276 '-4': {'-4': -4, '-3': -3, '-2': -2, '-1': -1}
Roger Meierbb267d42011-07-30 15:10:42 +0000277 };
278
Brian Forbisb5d6ea32018-08-25 23:39:29 -0400279 const mapMapTestOutput = client.testMapMap(1);
Roger Meierbb267d42011-07-30 15:10:42 +0000280
281
Brian Forbisb5d6ea32018-08-25 23:39:29 -0400282 for (let key in mapMapTestOutput) {
283 for (let key2 in mapMapTestOutput[key]) {
284 assert.equal(mapMapTestOutput[key][key2], mapMapTestExpectedResult[key][key2]);
Roger Meierbb267d42011-07-30 15:10:42 +0000285 }
286 }
Roger Meier08562732015-06-14 22:30:22 +0200287
Brian Forbisb5d6ea32018-08-25 23:39:29 -0400288 checkRecursively(assert, mapMapTestOutput, mapMapTestExpectedResult);
Roger Meierbb267d42011-07-30 15:10:42 +0000289 });
290
291
Brian Forbisb5d6ea32018-08-25 23:39:29 -0400292QUnit.module('Exception');
Roger Meierbb267d42011-07-30 15:10:42 +0000293
Brian Forbisb5d6ea32018-08-25 23:39:29 -0400294 QUnit.test('Xception', function(assert) {
295 assert.expect(2);
296 const done = assert.async();
Kazuki Matsudab909a382016-02-13 19:36:09 +0900297 try {
298 client.testException('Xception');
Brian Forbisb5d6ea32018-08-25 23:39:29 -0400299 assert.ok(false);
Kazuki Matsudab909a382016-02-13 19:36:09 +0900300 }catch (e) {
Brian Forbisb5d6ea32018-08-25 23:39:29 -0400301 assert.equal(e.errorCode, 1001);
302 assert.equal(e.message, 'Xception');
303 done();
Roger Meierbb267d42011-07-30 15:10:42 +0000304 }
305 });
306
Brian Forbisb5d6ea32018-08-25 23:39:29 -0400307 QUnit.test('no Exception', function(assert) {
308 assert.expect(1);
Kazuki Matsudab909a382016-02-13 19:36:09 +0900309 try {
310 client.testException('no Exception');
Brian Forbisb5d6ea32018-08-25 23:39:29 -0400311 assert.ok(true);
Kazuki Matsudab909a382016-02-13 19:36:09 +0900312 }catch (e) {
Brian Forbisb5d6ea32018-08-25 23:39:29 -0400313 assert.ok(false);
Roger Meierbb267d42011-07-30 15:10:42 +0000314 }
315 });
316
Brian Forbisb5d6ea32018-08-25 23:39:29 -0400317 QUnit.test('TException', function(assert) {
henriquea2de4102014-02-07 14:12:56 +0100318 //ThriftTest does not list TException as a legal exception so it will
Roger Meier08562732015-06-14 22:30:22 +0200319 // generate an exception on the server that does not propagate back to
henriquea2de4102014-02-07 14:12:56 +0100320 // the client. This test has been modified to equate to "no exception"
Brian Forbisb5d6ea32018-08-25 23:39:29 -0400321 assert.expect(1);
Kazuki Matsudab909a382016-02-13 19:36:09 +0900322 try {
323 client.testException('TException');
324 } catch (e) {
Brian Forbisb5d6ea32018-08-25 23:39:29 -0400325 //assert.ok(false);
Roger Meierbb267d42011-07-30 15:10:42 +0000326 }
Brian Forbisb5d6ea32018-08-25 23:39:29 -0400327 assert.ok(true);
Roger Meierbb267d42011-07-30 15:10:42 +0000328 });
329
330
Brian Forbisb5d6ea32018-08-25 23:39:29 -0400331QUnit.module('Insanity');
Roger Meierbb267d42011-07-30 15:10:42 +0000332
Brian Forbisb5d6ea32018-08-25 23:39:29 -0400333 const crazy = {
Kazuki Matsudab909a382016-02-13 19:36:09 +0900334 'userMap': { '5': 5, '8': 8 },
335 'xtructs': [{
336 'string_thing': 'Goodbye4',
337 'byte_thing': 4,
338 'i32_thing': 4,
Mustafa Senol Cosarf86845e2018-12-05 17:50:18 +0300339 'i64_thing': new Int64(4)
Nobuaki Sukegawa01ede042015-09-29 02:16:53 +0900340 },
341 {
Kazuki Matsudab909a382016-02-13 19:36:09 +0900342 'string_thing': 'Hello2',
343 'byte_thing': 2,
344 'i32_thing': 2,
Mustafa Senol Cosarf86845e2018-12-05 17:50:18 +0300345 'i64_thing': new Int64(2)
Nobuaki Sukegawa01ede042015-09-29 02:16:53 +0900346 }]
347 };
Brian Forbisb5d6ea32018-08-25 23:39:29 -0400348 QUnit.test('testInsanity', function(assert) {
349 const insanity = {
Kazuki Matsudab909a382016-02-13 19:36:09 +0900350 '1': {
351 '2': crazy,
352 '3': crazy
Roger Meierbb267d42011-07-30 15:10:42 +0000353 },
Kazuki Matsudab909a382016-02-13 19:36:09 +0900354 '2': { '6': { 'userMap': null, 'xtructs': null } }
Roger Meierbb267d42011-07-30 15:10:42 +0000355 };
Brian Forbisb5d6ea32018-08-25 23:39:29 -0400356 const res = client.testInsanity(new ThriftTest.Insanity(crazy));
357 assert.ok(res, JSON.stringify(res));
358 assert.ok(insanity, JSON.stringify(insanity));
Roger Meier4f8a5232011-09-09 08:17:02 +0000359
Brian Forbisb5d6ea32018-08-25 23:39:29 -0400360 checkRecursively(assert, res, insanity);
Roger Meierbb267d42011-07-30 15:10:42 +0000361 });
362
363
364//////////////////////////////////
365//Run same tests asynchronously
Roger Meierbb267d42011-07-30 15:10:42 +0000366
Brian Forbisb5d6ea32018-08-25 23:39:29 -0400367QUnit.module('Async');
Roger Meierbb267d42011-07-30 15:10:42 +0000368
Brian Forbisb5d6ea32018-08-25 23:39:29 -0400369 QUnit.test('Double', function(assert) {
370 assert.expect(1);
Roger Meierbb267d42011-07-30 15:10:42 +0000371
Brian Forbisb5d6ea32018-08-25 23:39:29 -0400372 const done = assert.async();
Roger Meierbb267d42011-07-30 15:10:42 +0000373 client.testDouble(3.14159265, function(result) {
Brian Forbisb5d6ea32018-08-25 23:39:29 -0400374 assert.equal(result, 3.14159265);
375 done();
Roger Meierbb267d42011-07-30 15:10:42 +0000376 });
377 });
378
Brian Forbisb5d6ea32018-08-25 23:39:29 -0400379 QUnit.test('Byte', function(assert) {
380 assert.expect(1);
Roger Meierbb267d42011-07-30 15:10:42 +0000381
Brian Forbisb5d6ea32018-08-25 23:39:29 -0400382 const done = assert.async();
Roger Meierbb267d42011-07-30 15:10:42 +0000383 client.testByte(0x01, function(result) {
Brian Forbisb5d6ea32018-08-25 23:39:29 -0400384 assert.equal(result, 0x01);
385 done();
Roger Meierbb267d42011-07-30 15:10:42 +0000386 });
387 });
388
Brian Forbisb5d6ea32018-08-25 23:39:29 -0400389 QUnit.test('I32', function(assert) {
390 assert.expect(2);
Roger Meierbb267d42011-07-30 15:10:42 +0000391
Brian Forbisb5d6ea32018-08-25 23:39:29 -0400392 const done = assert.async(2);
Kazuki Matsudab909a382016-02-13 19:36:09 +0900393 client.testI32(Math.pow(2, 30), function(result) {
Brian Forbisb5d6ea32018-08-25 23:39:29 -0400394 assert.equal(result, Math.pow(2, 30));
395 done();
Roger Meierbb267d42011-07-30 15:10:42 +0000396 });
397
Kazuki Matsudab909a382016-02-13 19:36:09 +0900398 client.testI32(Math.pow(-2, 31), function(result) {
Brian Forbisb5d6ea32018-08-25 23:39:29 -0400399 assert.equal(result, Math.pow(-2, 31));
400 done();
Roger Meierbb267d42011-07-30 15:10:42 +0000401 });
402 });
403
Brian Forbisb5d6ea32018-08-25 23:39:29 -0400404 QUnit.test('I64', function(assert) {
405 assert.expect(2);
Roger Meierbb267d42011-07-30 15:10:42 +0000406
Brian Forbisb5d6ea32018-08-25 23:39:29 -0400407 const done = assert.async(2);
Mustafa Senol Cosarf86845e2018-12-05 17:50:18 +0300408 client.testI64(int64_2_pow_60, function(result) {
409 assert.ok(int64_2_pow_60.equals(result));
Brian Forbisb5d6ea32018-08-25 23:39:29 -0400410 done();
henriquea2de4102014-02-07 14:12:56 +0100411 });
412
Mustafa Senol Cosarf86845e2018-12-05 17:50:18 +0300413 client.testI64(int64_minus_2_pow_60, function(result) {
414 assert.ok(int64_minus_2_pow_60.equals(result));
Brian Forbisb5d6ea32018-08-25 23:39:29 -0400415 done();
Roger Meierbb267d42011-07-30 15:10:42 +0000416 });
417 });