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