]> git.proxmox.com Git - ceph.git/blame - ceph/src/jaegertracing/thrift/lib/js/test/test-es6.js
buildsys: switch source download to quincy
[ceph.git] / ceph / src / jaegertracing / thrift / lib / js / test / test-es6.js
CommitLineData
f67539c2
TL
1/*
2 * 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 */
19 /* jshint -W100 */
20
21/*
22 * Fully Async JavaScript test suite for ThriftTest.thrift.
23 * These tests are designed to exercise the WebSocket transport
24 * (which is exclusively async).
25 *
26 * To compile client code for this test use:
27 * $ thrift -gen js:es6 ThriftTest.thrift
28 */
29
30
31
32// all Languages in UTF-8
33
34const 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ú, 粵語";
35
36function checkRecursively(assert, map1, map2) {
37 if (typeof map1 !== 'function' && typeof map2 !== 'function') {
38 if (!map1 || typeof map1 !== 'object') {
39 assert.equal(map1, map2);
40 } else {
41 for (var key in map1) {
42 checkRecursively(assert, map1[key], map2[key]);
43 }
44 }
45 }
46}
47
48QUnit.module('Base Types');
49
50 QUnit.test('Void', function( assert ) {
51 assert.expect(1);
52 const done = assert.async();
53 client.testVoid().then(function(result) {
54 assert.equal(result, undefined);
55 done();
56 });
57 });
58
59 QUnit.test('String', function( assert ) {
60 assert.expect(3);
61 const done = assert.async(3);
62 client.testString('').then(function(result) {
63 assert.equal(result, '');
64 done();
65 });
66 client.testString(stringTest).then(function(result) {
67 assert.equal(result, stringTest);
68 done();
69 });
70 var specialCharacters = 'quote: \" backslash:' +
71 ' forwardslash-escaped: \/ ' +
72 ' backspace: \b formfeed: \f newline: \n return: \r tab: ' +
73 ' now-all-of-them-together: "\\\/\b\n\r\t' +
74 ' now-a-bunch-of-junk: !@#$%&()(&%$#{}{}<><><';
75 client.testString(specialCharacters).then(function(result) {
76 assert.equal(result, specialCharacters);
77 done();
78 });
79 });
80
81 QUnit.test('Double', function( assert ) {
82 assert.expect(4);
83 const done = assert.async(4);
84 client.testDouble(0).then(function(result) {
85 assert.equal(result, 0);
86 done();
87 });
88 client.testDouble(-1).then(function(result) {
89 assert.equal(result, -1);
90 done();
91 });
92 client.testDouble(3.14).then(function(result) {
93 assert.equal(result, 3.14);
94 done();
95 });
96 client.testDouble(Math.pow(2, 60)).then(function(result) {
97 assert.equal(result, Math.pow(2, 60));
98 done();
99 });
100 });
101 // TODO: add testBinary()
102 QUnit.test('Byte', function( assert ) {
103 assert.expect(2);
104 const done = assert.async(2);
105 client.testByte(0).then(function(result) {
106 assert.equal(result, 0);
107 done();
108 });
109 client.testByte(0x01).then(function(result) {
110 assert.equal(result, 0x01);
111 done();
112 });
113 });
114 QUnit.test('I32', function( assert ) {
115 assert.expect(3);
116 const done = assert.async(3);
117 client.testI32(0).then(function(result) {
118 assert.equal(result, 0);
119 done();
120 });
121 client.testI32(Math.pow(2, 30)).then(function(result) {
122 assert.equal(result, Math.pow(2, 30));
123 done();
124 });
125 client.testI32(-Math.pow(2, 30)).then(function(result) {
126 assert.equal(result, -Math.pow(2, 30));
127 done();
128 });
129 });
130 QUnit.test('I64', function( assert ) {
131 assert.expect(3);
132 const done = assert.async(3);
133 client.testI64(0).then(function(result) {
134 assert.equal(result, 0);
135 done();
136 });
137 //This is usually 2^60 but JS cannot represent anything over 2^52 accurately
138 client.testI64(Math.pow(2, 52)).then(function(result) {
139 assert.equal(result, Math.pow(2, 52));
140 done();
141 });
142 client.testI64(-Math.pow(2, 52)).then(function(result) {
143 assert.equal(result, -Math.pow(2, 52));
144 done();
145 });
146 });
147
148
149QUnit.module('Structured Types');
150
151 QUnit.test('Struct', function( assert ) {
152 assert.expect(5);
153 const done = assert.async();
154 var structTestInput = new ThriftTest.Xtruct();
155 structTestInput.string_thing = 'worked';
156 structTestInput.byte_thing = 0x01;
157 structTestInput.i32_thing = Math.pow(2, 30);
158 //This is usually 2^60 but JS cannot represent anything over 2^52 accurately
159 structTestInput.i64_thing = Math.pow(2, 52);
160
161 client.testStruct(structTestInput).then(function(result) {
162 assert.equal(result.string_thing, structTestInput.string_thing);
163 assert.equal(result.byte_thing, structTestInput.byte_thing);
164 assert.equal(result.i32_thing, structTestInput.i32_thing);
165 assert.equal(result.i64_thing, structTestInput.i64_thing);
166 assert.equal(JSON.stringify(result), JSON.stringify(structTestInput));
167 done();
168 });
169 });
170
171 QUnit.test('Nest', function( assert ) {
172 assert.expect(7);
173 const done = assert.async();
174 var xtrTestInput = new ThriftTest.Xtruct();
175 xtrTestInput.string_thing = 'worked';
176 xtrTestInput.byte_thing = 0x01;
177 xtrTestInput.i32_thing = Math.pow(2, 30);
178 //This is usually 2^60 but JS cannot represent anything over 2^52 accurately
179 xtrTestInput.i64_thing = Math.pow(2, 52);
180
181 var nestTestInput = new ThriftTest.Xtruct2();
182 nestTestInput.byte_thing = 0x02;
183 nestTestInput.struct_thing = xtrTestInput;
184 nestTestInput.i32_thing = Math.pow(2, 15);
185
186 client.testNest(nestTestInput).then(function(result) {
187 assert.equal(result.byte_thing, nestTestInput.byte_thing);
188 assert.equal(result.struct_thing.string_thing, nestTestInput.struct_thing.string_thing);
189 assert.equal(result.struct_thing.byte_thing, nestTestInput.struct_thing.byte_thing);
190 assert.equal(result.struct_thing.i32_thing, nestTestInput.struct_thing.i32_thing);
191 assert.equal(result.struct_thing.i64_thing, nestTestInput.struct_thing.i64_thing);
192 assert.equal(result.i32_thing, nestTestInput.i32_thing);
193 assert.equal(JSON.stringify(result), JSON.stringify(nestTestInput));
194 done();
195 });
196 });
197
198 QUnit.test('Map', function( assert ) {
199 assert.expect(3);
200 const done = assert.async();
201 var mapTestInput = {7: 77, 8: 88, 9: 99};
202
203 client.testMap(mapTestInput).then(function(result) {
204 for (var key in result) {
205 assert.equal(result[key], mapTestInput[key]);
206 }
207 done();
208 });
209 });
210
211 QUnit.test('StringMap', function( assert ) {
212 assert.expect(6);
213 const done = assert.async();
214 var mapTestInput = {
215 'a': '123', 'a b': 'with spaces ', 'same': 'same', '0': 'numeric key',
216 'longValue': stringTest, stringTest: 'long key'
217 };
218
219 client.testStringMap(mapTestInput).then(function(result) {
220 for (var key in result) {
221 assert.equal(result[key], mapTestInput[key]);
222 }
223 done();
224 });
225 });
226
227 QUnit.test('Set', function( assert ) {
228 assert.expect(1);
229 const done = assert.async();
230 var setTestInput = [1, 2, 3];
231 client.testSet(setTestInput).then(function(result) {
232 assert.ok(result, setTestInput);
233 done();
234 });
235 });
236
237 QUnit.test('List', function( assert ) {
238 assert.expect(1);
239 const done = assert.async();
240 var listTestInput = [1, 2, 3];
241 client.testList(listTestInput).then(function(result) {
242 assert.ok(result, listTestInput);
243 done();
244 });
245 });
246
247 QUnit.test('Enum', function( assert ) {
248 assert.expect(1);
249 const done = assert.async();
250 client.testEnum(ThriftTest.Numberz.ONE).then(function(result) {
251 assert.equal(result, ThriftTest.Numberz.ONE);
252 done();
253 });
254 });
255
256 QUnit.test('TypeDef', function( assert ) {
257 assert.expect(1);
258 const done = assert.async();
259 client.testTypedef(69).then(function(result) {
260 assert.equal(result, 69);
261 done();
262 });
263 });
264
265
266QUnit.module('deeper!');
267
268 QUnit.test('MapMap', function( assert ) {
269 assert.expect(16);
270 const done = assert.async();
271 var mapMapTestExpectedResult = {
272 '4': {'1': 1, '2': 2, '3': 3, '4': 4},
273 '-4': {'-4': -4, '-3': -3, '-2': -2, '-1': -1}
274 };
275
276 client.testMapMap(1).then(function(result) {
277 for (var key in result) {
278 for (var key2 in result[key]) {
279 assert.equal(result[key][key2], mapMapTestExpectedResult[key][key2]);
280 }
281 }
282 checkRecursively(assert, result, mapMapTestExpectedResult);
283 done();
284 });
285 });
286
287
288QUnit.module('Exception');
289
290 QUnit.test('Xception', function( assert ) {
291 assert.expect(2);
292 const done = assert.async();
293 client.testException('Xception').then(function(res) {
294 assert.ok(false);
295 }).catch(function(e) {
296
297 console.log(`Exception exception e`);
298 console.log(e);
299 console.log(JSON.stringify(e, null, 2));
300
301 assert.equal(e.errorCode, 1001);
302 assert.equal(e.message, 'Xception');
303 done();
304 });
305 });
306
307 QUnit.test('no Exception', function( assert ) {
308 assert.expect(1);
309 const done = assert.async();
310 client.testException('no Exception').then(function(e) {
311 assert.ok(!e);
312 done();
313 });
314 });
315
316QUnit.module('Insanity');
317
318 QUnit.test('testInsanity', function( assert ) {
319 assert.expect(24);
320 const done = assert.async();
321 var insanity = {
322 '1': {
323 '2': {
324 'userMap': { '5': 5, '8': 8 },
325 'xtructs': [{
326 'string_thing': 'Goodbye4',
327 'byte_thing': 4,
328 'i32_thing': 4,
329 'i64_thing': 4
330 },
331 {
332 'string_thing': 'Hello2',
333 'byte_thing': 2,
334 'i32_thing': 2,
335 'i64_thing': 2
336 }
337 ]
338 },
339 '3': {
340 'userMap': { '5': 5, '8': 8 },
341 'xtructs': [{
342 'string_thing': 'Goodbye4',
343 'byte_thing': 4,
344 'i32_thing': 4,
345 'i64_thing': 4
346 },
347 {
348 'string_thing': 'Hello2',
349 'byte_thing': 2,
350 'i32_thing': 2,
351 'i64_thing': 2
352 }
353 ]
354 }
355 },
356 '2': { '6': { 'userMap': null, 'xtructs': null } }
357 };
358 client.testInsanity(new ThriftTest.Insanity()).then(function(res) {
359 assert.ok(res, JSON.stringify(res));
360 assert.ok(insanity, JSON.stringify(insanity));
361 checkRecursively(assert, res, insanity);
362 done();
363 });
364 });
365
366QUnit.module('Oneway');
367 QUnit.test('testOneway', function( assert ) {
368 assert.expect(1);
369 const done = assert.async();
370 client.testOneway(1).then(function(result) {
371 assert.equal(result, undefined);
372 done();
373 });
374 });