henrique | a2de410 | 2014-02-07 14:12:56 +0100 | [diff] [blame] | 1 | /* |
Roger Meier | bb267d4 | 2011-07-30 15:10:42 +0000 | [diff] [blame] | 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 | */ |
Henrique Mendonça | 095ddb7 | 2013-09-20 19:38:03 +0200 | [diff] [blame] | 19 | /* jshint -W100 */ |
Roger Meier | 0856273 | 2015-06-14 22:30:22 +0200 | [diff] [blame] | 20 | |
Roger Meier | bb267d4 | 2011-07-30 15:10:42 +0000 | [diff] [blame] | 21 | /* |
henrique | a2de410 | 2014-02-07 14:12:56 +0100 | [diff] [blame] | 22 | * 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 | * |
| 26 | * Synchronous blocking calls should be identical in both |
| 27 | * Normal and jQuery interfaces. All synchronous tests belong |
| 28 | * here. |
Roger Meier | 0856273 | 2015-06-14 22:30:22 +0200 | [diff] [blame] | 29 | * |
| 30 | * Asynchronous success callbacks passed as the last parameter |
henrique | a2de410 | 2014-02-07 14:12:56 +0100 | [diff] [blame] | 31 | * of an RPC call should be identical in both Normal and jQuery |
| 32 | * interfaces. Async success tests belong here. |
Roger Meier | 0856273 | 2015-06-14 22:30:22 +0200 | [diff] [blame] | 33 | * |
henrique | a2de410 | 2014-02-07 14:12:56 +0100 | [diff] [blame] | 34 | * 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 Meier | 0856273 | 2015-06-14 22:30:22 +0200 | [diff] [blame] | 37 | * tests also belong in test-jq.js. Do not create any jQuery |
henrique | a2de410 | 2014-02-07 14:12:56 +0100 | [diff] [blame] | 38 | * 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 Meier | 0856273 | 2015-06-14 22:30:22 +0200 | [diff] [blame] | 46 | * ++ test-nojq.js for "-gen js" only tests |
henrique | a2de410 | 2014-02-07 14:12:56 +0100 | [diff] [blame] | 47 | * ++ test-jq.js for "-gen js:jquery" only tests |
Roger Meier | bb267d4 | 2011-07-30 15:10:42 +0000 | [diff] [blame] | 48 | */ |
| 49 | |
| 50 | var transport = new Thrift.Transport("/service"); |
| 51 | var protocol = new Thrift.Protocol(transport); |
| 52 | var client = new ThriftTest.ThriftTestClient(protocol); |
| 53 | |
Nobuaki Sukegawa | 72f8809 | 2015-05-10 23:35:29 +0900 | [diff] [blame] | 54 | // Work around for old API used by QUnitAdapter of jsTestDriver |
| 55 | if (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 Sukegawa | 6defea5 | 2015-11-14 17:36:29 +0900 | [diff] [blame^] | 61 | if (details.message) console.log(details.message); |
Nobuaki Sukegawa | 72f8809 | 2015-05-10 23:35:29 +0900 | [diff] [blame] | 62 | console.log('Expected: ' + details.expected); |
| 63 | console.log('Actual : ' + details.actual); |
| 64 | console.log('======================'); |
| 65 | } |
| 66 | }); |
| 67 | } |
| 68 | |
Roger Meier | bb267d4 | 2011-07-30 15:10:42 +0000 | [diff] [blame] | 69 | // all Languages in UTF-8 |
| 70 | 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ú, 粵語"; |
Roger Meier | 0856273 | 2015-06-14 22:30:22 +0200 | [diff] [blame] | 71 | |
Roger Meier | 4f8a523 | 2011-09-09 08:17:02 +0000 | [diff] [blame] | 72 | function checkRecursively(map1, map2) { |
| 73 | if (typeof map1 !== 'function' && typeof map2 !== 'function') { |
| 74 | if (!map1 || typeof map1 !== 'object') { |
Roger Meier | b661e83 | 2012-04-15 15:58:43 +0000 | [diff] [blame] | 75 | equal(map1, map2); |
Roger Meier | 4f8a523 | 2011-09-09 08:17:02 +0000 | [diff] [blame] | 76 | } else { |
| 77 | for (var key in map1) { |
| 78 | checkRecursively(map1[key], map2[key]); |
| 79 | } |
| 80 | } |
| 81 | } |
| 82 | } |
Roger Meier | bb267d4 | 2011-07-30 15:10:42 +0000 | [diff] [blame] | 83 | |
| 84 | module("Base Types"); |
| 85 | |
| 86 | test("Void", function() { |
Roger Meier | b661e83 | 2012-04-15 15:58:43 +0000 | [diff] [blame] | 87 | equal(client.testVoid(), undefined); |
Roger Meier | bb267d4 | 2011-07-30 15:10:42 +0000 | [diff] [blame] | 88 | }); |
Nobuaki Sukegawa | 6defea5 | 2015-11-14 17:36:29 +0900 | [diff] [blame^] | 89 | test("Binary (String)", function() { |
| 90 | var binary = ''; |
| 91 | for (var v = 255; v >= 0; --v) { |
| 92 | binary += String.fromCharCode(v); |
| 93 | } |
| 94 | equal(client.testBinary(binary), binary); |
| 95 | }); |
| 96 | test("Binary (Uint8Array)", function() { |
| 97 | 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 | }); |
Roger Meier | bb267d4 | 2011-07-30 15:10:42 +0000 | [diff] [blame] | 107 | test("String", function() { |
Henrique Mendonca | 6af2ec0 | 2012-09-27 13:14:36 +0000 | [diff] [blame] | 108 | equal(client.testString(''), ''); |
Roger Meier | b661e83 | 2012-04-15 15:58:43 +0000 | [diff] [blame] | 109 | equal(client.testString(stringTest), stringTest); |
Roger Meier | bb267d4 | 2011-07-30 15:10:42 +0000 | [diff] [blame] | 110 | |
| 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: !@#$%&()(&%$#{}{}<><><'; |
Roger Meier | b661e83 | 2012-04-15 15:58:43 +0000 | [diff] [blame] | 116 | equal(client.testString(specialCharacters),specialCharacters); |
Roger Meier | bb267d4 | 2011-07-30 15:10:42 +0000 | [diff] [blame] | 117 | }); |
| 118 | test("Double", function() { |
Henrique Mendonca | 6af2ec0 | 2012-09-27 13:14:36 +0000 | [diff] [blame] | 119 | equal(client.testDouble(0), 0); |
| 120 | equal(client.testDouble(-1), -1); |
Roger Meier | b661e83 | 2012-04-15 15:58:43 +0000 | [diff] [blame] | 121 | equal(client.testDouble(3.14), 3.14); |
Henrique Mendonca | 6af2ec0 | 2012-09-27 13:14:36 +0000 | [diff] [blame] | 122 | equal(client.testDouble(Math.pow(2,60)), Math.pow(2,60)); |
Roger Meier | bb267d4 | 2011-07-30 15:10:42 +0000 | [diff] [blame] | 123 | }); |
| 124 | test("Byte", function() { |
Henrique Mendonca | 6af2ec0 | 2012-09-27 13:14:36 +0000 | [diff] [blame] | 125 | equal(client.testByte(0), 0); |
Roger Meier | b661e83 | 2012-04-15 15:58:43 +0000 | [diff] [blame] | 126 | equal(client.testByte(0x01), 0x01); |
Roger Meier | bb267d4 | 2011-07-30 15:10:42 +0000 | [diff] [blame] | 127 | }); |
| 128 | test("I32", function() { |
Henrique Mendonca | 6af2ec0 | 2012-09-27 13:14:36 +0000 | [diff] [blame] | 129 | equal(client.testI32(0), 0); |
Roger Meier | b661e83 | 2012-04-15 15:58:43 +0000 | [diff] [blame] | 130 | equal(client.testI32(Math.pow(2,30)), Math.pow(2,30)); |
Henrique Mendonca | 6af2ec0 | 2012-09-27 13:14:36 +0000 | [diff] [blame] | 131 | equal(client.testI32(-Math.pow(2,30)), -Math.pow(2,30)); |
Roger Meier | bb267d4 | 2011-07-30 15:10:42 +0000 | [diff] [blame] | 132 | }); |
| 133 | test("I64", function() { |
Henrique Mendonca | 6af2ec0 | 2012-09-27 13:14:36 +0000 | [diff] [blame] | 134 | equal(client.testI64(0), 0); |
henrique | a2de410 | 2014-02-07 14:12:56 +0100 | [diff] [blame] | 135 | //This is usually 2^60 but JS cannot represent anything over 2^52 accurately |
| 136 | equal(client.testI64(Math.pow(2,52)), Math.pow(2,52)); |
| 137 | equal(client.testI64(-Math.pow(2,52)), -Math.pow(2,52)); |
Roger Meier | bb267d4 | 2011-07-30 15:10:42 +0000 | [diff] [blame] | 138 | }); |
| 139 | |
| 140 | |
| 141 | module("Structured Types"); |
| 142 | |
| 143 | test("Struct", function() { |
Roger Meier | edf0d1d | 2011-08-03 21:21:43 +0000 | [diff] [blame] | 144 | var structTestInput = new ThriftTest.Xtruct(); |
| 145 | structTestInput.string_thing = 'worked'; |
| 146 | structTestInput.byte_thing = 0x01; |
| 147 | structTestInput.i32_thing = Math.pow(2,30); |
henrique | a2de410 | 2014-02-07 14:12:56 +0100 | [diff] [blame] | 148 | //This is usually 2^60 but JS cannot represent anything over 2^52 accurately |
| 149 | structTestInput.i64_thing = Math.pow(2,52); |
Roger Meier | bb267d4 | 2011-07-30 15:10:42 +0000 | [diff] [blame] | 150 | |
| 151 | var structTestOutput = client.testStruct(structTestInput); |
| 152 | |
Roger Meier | b661e83 | 2012-04-15 15:58:43 +0000 | [diff] [blame] | 153 | 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 Meier | 0856273 | 2015-06-14 22:30:22 +0200 | [diff] [blame] | 157 | |
Roger Meier | b661e83 | 2012-04-15 15:58:43 +0000 | [diff] [blame] | 158 | equal(JSON.stringify(structTestOutput), JSON.stringify(structTestInput)); |
Roger Meier | bb267d4 | 2011-07-30 15:10:42 +0000 | [diff] [blame] | 159 | }); |
| 160 | |
| 161 | test("Nest", function() { |
Roger Meier | edf0d1d | 2011-08-03 21:21:43 +0000 | [diff] [blame] | 162 | var xtrTestInput = new ThriftTest.Xtruct(); |
| 163 | xtrTestInput.string_thing = 'worked'; |
| 164 | xtrTestInput.byte_thing = 0x01; |
| 165 | xtrTestInput.i32_thing = Math.pow(2,30); |
henrique | a2de410 | 2014-02-07 14:12:56 +0100 | [diff] [blame] | 166 | //This is usually 2^60 but JS cannot represent anything over 2^52 accurately |
| 167 | xtrTestInput.i64_thing = Math.pow(2,52); |
Roger Meier | 0856273 | 2015-06-14 22:30:22 +0200 | [diff] [blame] | 168 | |
Roger Meier | edf0d1d | 2011-08-03 21:21:43 +0000 | [diff] [blame] | 169 | var nestTestInput = new ThriftTest.Xtruct2(); |
| 170 | nestTestInput.byte_thing = 0x02; |
| 171 | nestTestInput.struct_thing = xtrTestInput; |
| 172 | nestTestInput.i32_thing = Math.pow(2,15); |
Roger Meier | 0856273 | 2015-06-14 22:30:22 +0200 | [diff] [blame] | 173 | |
Roger Meier | bb267d4 | 2011-07-30 15:10:42 +0000 | [diff] [blame] | 174 | var nestTestOutput = client.testNest(nestTestInput); |
Roger Meier | 0856273 | 2015-06-14 22:30:22 +0200 | [diff] [blame] | 175 | |
Roger Meier | b661e83 | 2012-04-15 15:58:43 +0000 | [diff] [blame] | 176 | 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 Meier | 0856273 | 2015-06-14 22:30:22 +0200 | [diff] [blame] | 182 | |
Roger Meier | b661e83 | 2012-04-15 15:58:43 +0000 | [diff] [blame] | 183 | equal(JSON.stringify(nestTestOutput), JSON.stringify(nestTestInput)); |
Roger Meier | bb267d4 | 2011-07-30 15:10:42 +0000 | [diff] [blame] | 184 | }); |
| 185 | |
| 186 | test("Map", function() { |
| 187 | var mapTestInput = {7:77, 8:88, 9:99}; |
| 188 | |
Roger Meier | edf0d1d | 2011-08-03 21:21:43 +0000 | [diff] [blame] | 189 | var mapTestOutput = client.testMap(mapTestInput); |
Roger Meier | bb267d4 | 2011-07-30 15:10:42 +0000 | [diff] [blame] | 190 | |
| 191 | for (var key in mapTestOutput) { |
Roger Meier | b661e83 | 2012-04-15 15:58:43 +0000 | [diff] [blame] | 192 | equal(mapTestOutput[key], mapTestInput[key]); |
Roger Meier | bb267d4 | 2011-07-30 15:10:42 +0000 | [diff] [blame] | 193 | } |
| 194 | }); |
| 195 | |
| 196 | test("StringMap", function() { |
| 197 | var mapTestInput = { |
| 198 | "a":"123", "a b":"with spaces ", "same":"same", "0":"numeric key", |
| 199 | "longValue":stringTest, stringTest:"long key" |
| 200 | }; |
| 201 | |
Roger Meier | edf0d1d | 2011-08-03 21:21:43 +0000 | [diff] [blame] | 202 | var mapTestOutput = client.testStringMap(mapTestInput); |
Roger Meier | bb267d4 | 2011-07-30 15:10:42 +0000 | [diff] [blame] | 203 | |
| 204 | for (var key in mapTestOutput) { |
Roger Meier | b661e83 | 2012-04-15 15:58:43 +0000 | [diff] [blame] | 205 | equal(mapTestOutput[key], mapTestInput[key]); |
Roger Meier | bb267d4 | 2011-07-30 15:10:42 +0000 | [diff] [blame] | 206 | } |
| 207 | }); |
| 208 | |
| 209 | test("Set", function() { |
Roger Meier | edf0d1d | 2011-08-03 21:21:43 +0000 | [diff] [blame] | 210 | var setTestInput = [1,2,3]; |
Roger Meier | bb267d4 | 2011-07-30 15:10:42 +0000 | [diff] [blame] | 211 | ok(client.testSet(setTestInput), setTestInput); |
| 212 | }); |
| 213 | |
| 214 | test("List", function() { |
Roger Meier | edf0d1d | 2011-08-03 21:21:43 +0000 | [diff] [blame] | 215 | var listTestInput = [1,2,3]; |
Roger Meier | bb267d4 | 2011-07-30 15:10:42 +0000 | [diff] [blame] | 216 | ok(client.testList(listTestInput), listTestInput); |
| 217 | }); |
| 218 | |
| 219 | test("Enum", function() { |
Roger Meier | b661e83 | 2012-04-15 15:58:43 +0000 | [diff] [blame] | 220 | equal(client.testEnum(ThriftTest.Numberz.ONE), ThriftTest.Numberz.ONE); |
Roger Meier | bb267d4 | 2011-07-30 15:10:42 +0000 | [diff] [blame] | 221 | }); |
| 222 | |
| 223 | test("TypeDef", function() { |
Roger Meier | b661e83 | 2012-04-15 15:58:43 +0000 | [diff] [blame] | 224 | equal(client.testTypedef(69), 69); |
Roger Meier | bb267d4 | 2011-07-30 15:10:42 +0000 | [diff] [blame] | 225 | }); |
| 226 | |
Jens Geyer | 329d59a | 2014-06-19 22:11:53 +0200 | [diff] [blame] | 227 | test("Skip", function() { |
| 228 | var structTestInput = new ThriftTest.Xtruct(); |
| 229 | var modifiedClient = new ThriftTest.ThriftTestClient(protocol); |
| 230 | |
| 231 | modifiedClient.recv_testStruct = function() { |
| 232 | var input = modifiedClient.input; |
| 233 | var xtruct3 = new ThriftTest.Xtruct3(); |
| 234 | |
| 235 | input.readMessageBegin(); |
| 236 | input.readStructBegin(); |
| 237 | |
Roger Meier | 0856273 | 2015-06-14 22:30:22 +0200 | [diff] [blame] | 238 | // read Xtruct data with Xtruct3 |
Jens Geyer | 329d59a | 2014-06-19 22:11:53 +0200 | [diff] [blame] | 239 | 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'; |
| 253 | structTestInput.byte_thing = 0x01; |
| 254 | structTestInput.i32_thing = Math.pow(2,30); |
| 255 | structTestInput.i64_thing = Math.pow(2,52); |
| 256 | |
| 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 Meier | bb267d4 | 2011-07-30 15:10:42 +0000 | [diff] [blame] | 266 | |
| 267 | module("deeper!"); |
| 268 | |
| 269 | test("MapMap", function() { |
| 270 | var mapMapTestExpectedResult = { |
| 271 | "4":{"1":1,"2":2,"3":3,"4":4}, |
| 272 | "-4":{"-4":-4, "-3":-3, "-2":-2, "-1":-1} |
| 273 | }; |
| 274 | |
| 275 | var mapMapTestOutput = client.testMapMap(1); |
| 276 | |
| 277 | |
| 278 | for (var key in mapMapTestOutput) { |
| 279 | for (var key2 in mapMapTestOutput[key]) { |
Roger Meier | b661e83 | 2012-04-15 15:58:43 +0000 | [diff] [blame] | 280 | equal(mapMapTestOutput[key][key2], mapMapTestExpectedResult[key][key2]); |
Roger Meier | bb267d4 | 2011-07-30 15:10:42 +0000 | [diff] [blame] | 281 | } |
| 282 | } |
Roger Meier | 0856273 | 2015-06-14 22:30:22 +0200 | [diff] [blame] | 283 | |
Roger Meier | 4f8a523 | 2011-09-09 08:17:02 +0000 | [diff] [blame] | 284 | checkRecursively(mapMapTestOutput, mapMapTestExpectedResult); |
Roger Meier | bb267d4 | 2011-07-30 15:10:42 +0000 | [diff] [blame] | 285 | }); |
| 286 | |
| 287 | |
| 288 | module("Exception"); |
| 289 | |
| 290 | test("Xception", function() { |
| 291 | expect(2); |
| 292 | try{ |
| 293 | client.testException("Xception"); |
| 294 | }catch(e){ |
Roger Meier | b661e83 | 2012-04-15 15:58:43 +0000 | [diff] [blame] | 295 | equal(e.errorCode, 1001); |
| 296 | equal(e.message, "Xception"); |
Roger Meier | bb267d4 | 2011-07-30 15:10:42 +0000 | [diff] [blame] | 297 | } |
| 298 | }); |
| 299 | |
Roger Meier | b661e83 | 2012-04-15 15:58:43 +0000 | [diff] [blame] | 300 | test("no Exception", 0, function() { |
Roger Meier | bb267d4 | 2011-07-30 15:10:42 +0000 | [diff] [blame] | 301 | try{ |
| 302 | client.testException("no Exception"); |
| 303 | }catch(e){ |
| 304 | ok(false); |
| 305 | } |
| 306 | }); |
| 307 | |
Roger Meier | 8ebe0d9 | 2013-01-06 14:33:39 +0100 | [diff] [blame] | 308 | test("TException", function() { |
henrique | a2de410 | 2014-02-07 14:12:56 +0100 | [diff] [blame] | 309 | //ThriftTest does not list TException as a legal exception so it will |
Roger Meier | 0856273 | 2015-06-14 22:30:22 +0200 | [diff] [blame] | 310 | // generate an exception on the server that does not propagate back to |
henrique | a2de410 | 2014-02-07 14:12:56 +0100 | [diff] [blame] | 311 | // the client. This test has been modified to equate to "no exception" |
Roger Meier | bb267d4 | 2011-07-30 15:10:42 +0000 | [diff] [blame] | 312 | expect(1); |
| 313 | try{ |
Roger Meier | 8ebe0d9 | 2013-01-06 14:33:39 +0100 | [diff] [blame] | 314 | client.testException("TException"); |
Roger Meier | bb267d4 | 2011-07-30 15:10:42 +0000 | [diff] [blame] | 315 | } catch(e) { |
henrique | a2de410 | 2014-02-07 14:12:56 +0100 | [diff] [blame] | 316 | //ok(false); |
Roger Meier | bb267d4 | 2011-07-30 15:10:42 +0000 | [diff] [blame] | 317 | } |
henrique | a2de410 | 2014-02-07 14:12:56 +0100 | [diff] [blame] | 318 | ok(true); |
Roger Meier | bb267d4 | 2011-07-30 15:10:42 +0000 | [diff] [blame] | 319 | }); |
| 320 | |
| 321 | |
| 322 | module("Insanity"); |
| 323 | |
Nobuaki Sukegawa | 01ede04 | 2015-09-29 02:16:53 +0900 | [diff] [blame] | 324 | var crazy = { |
| 325 | "userMap":{ "5":5, "8":8 }, |
| 326 | "xtructs":[{ |
| 327 | "string_thing":"Goodbye4", |
| 328 | "byte_thing":4, |
| 329 | "i32_thing":4, |
| 330 | "i64_thing":4 |
| 331 | }, |
| 332 | { |
| 333 | "string_thing":"Hello2", |
| 334 | "byte_thing":2, |
| 335 | "i32_thing":2, |
| 336 | "i64_thing":2 |
| 337 | }] |
| 338 | }; |
Roger Meier | bb267d4 | 2011-07-30 15:10:42 +0000 | [diff] [blame] | 339 | test("testInsanity", function() { |
| 340 | var insanity = { |
| 341 | "1":{ |
Nobuaki Sukegawa | 01ede04 | 2015-09-29 02:16:53 +0900 | [diff] [blame] | 342 | "2":crazy, |
| 343 | "3":crazy |
Roger Meier | bb267d4 | 2011-07-30 15:10:42 +0000 | [diff] [blame] | 344 | }, |
| 345 | "2":{ "6":{ "userMap":null, "xtructs":null } } |
| 346 | }; |
Nobuaki Sukegawa | 01ede04 | 2015-09-29 02:16:53 +0900 | [diff] [blame] | 347 | var res = client.testInsanity(new ThriftTest.Insanity(crazy)); |
Roger Meier | bb267d4 | 2011-07-30 15:10:42 +0000 | [diff] [blame] | 348 | ok(res, JSON.stringify(res)); |
| 349 | ok(insanity, JSON.stringify(insanity)); |
Roger Meier | 4f8a523 | 2011-09-09 08:17:02 +0000 | [diff] [blame] | 350 | |
| 351 | checkRecursively(res, insanity); |
Roger Meier | bb267d4 | 2011-07-30 15:10:42 +0000 | [diff] [blame] | 352 | }); |
| 353 | |
| 354 | |
| 355 | ////////////////////////////////// |
| 356 | //Run same tests asynchronously |
Roger Meier | bb267d4 | 2011-07-30 15:10:42 +0000 | [diff] [blame] | 357 | |
| 358 | module("Async"); |
| 359 | |
| 360 | test("Double", function() { |
| 361 | expect( 1 ); |
| 362 | |
| 363 | QUnit.stop(); |
| 364 | client.testDouble(3.14159265, function(result) { |
Roger Meier | b661e83 | 2012-04-15 15:58:43 +0000 | [diff] [blame] | 365 | equal(result, 3.14159265); |
Roger Meier | bb267d4 | 2011-07-30 15:10:42 +0000 | [diff] [blame] | 366 | QUnit.start(); |
| 367 | }); |
| 368 | }); |
| 369 | |
| 370 | test("Byte", function() { |
| 371 | expect( 1 ); |
| 372 | |
| 373 | QUnit.stop(); |
| 374 | client.testByte(0x01, function(result) { |
Roger Meier | b661e83 | 2012-04-15 15:58:43 +0000 | [diff] [blame] | 375 | equal(result, 0x01); |
Roger Meier | bb267d4 | 2011-07-30 15:10:42 +0000 | [diff] [blame] | 376 | QUnit.start(); |
| 377 | }); |
| 378 | }); |
| 379 | |
| 380 | test("I32", function() { |
henrique | a2de410 | 2014-02-07 14:12:56 +0100 | [diff] [blame] | 381 | expect( 2 ); |
Roger Meier | bb267d4 | 2011-07-30 15:10:42 +0000 | [diff] [blame] | 382 | |
| 383 | QUnit.stop(); |
| 384 | client.testI32(Math.pow(2,30), function(result) { |
Roger Meier | b661e83 | 2012-04-15 15:58:43 +0000 | [diff] [blame] | 385 | equal(result, Math.pow(2,30)); |
Roger Meier | bb267d4 | 2011-07-30 15:10:42 +0000 | [diff] [blame] | 386 | QUnit.start(); |
| 387 | }); |
| 388 | |
| 389 | QUnit.stop(); |
henrique | a2de410 | 2014-02-07 14:12:56 +0100 | [diff] [blame] | 390 | client.testI32(Math.pow(-2,31), function(result) { |
Roger Meier | b661e83 | 2012-04-15 15:58:43 +0000 | [diff] [blame] | 391 | equal(result, Math.pow(-2,31)); |
Roger Meier | bb267d4 | 2011-07-30 15:10:42 +0000 | [diff] [blame] | 392 | QUnit.start(); |
| 393 | }); |
| 394 | }); |
| 395 | |
| 396 | test("I64", function() { |
Roger Meier | bb267d4 | 2011-07-30 15:10:42 +0000 | [diff] [blame] | 397 | expect( 2 ); |
| 398 | |
| 399 | QUnit.stop(); |
henrique | a2de410 | 2014-02-07 14:12:56 +0100 | [diff] [blame] | 400 | //This is usually 2^60 but JS cannot represent anything over 2^52 accurately |
| 401 | client.testI64(Math.pow(2,52), function(result) { |
| 402 | equal(result, Math.pow(2,52)); |
Roger Meier | bb267d4 | 2011-07-30 15:10:42 +0000 | [diff] [blame] | 403 | QUnit.start(); |
henrique | a2de410 | 2014-02-07 14:12:56 +0100 | [diff] [blame] | 404 | }); |
| 405 | |
| 406 | QUnit.stop(); |
| 407 | //This is usually 2^60 but JS cannot represent anything over 2^52 accurately |
| 408 | client.testI64(Math.pow(-2,52), function(result) { |
| 409 | equal(result, Math.pow(-2,52)); |
| 410 | QUnit.start(); |
Roger Meier | bb267d4 | 2011-07-30 15:10:42 +0000 | [diff] [blame] | 411 | }); |
| 412 | }); |