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 | bb267d4 | 2011-07-30 15:10:42 +0000 | [diff] [blame] | 20 | |
| 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. |
| 29 | * |
Konrad Grochowski | 3b5dacb | 2014-11-24 10:55:31 +0100 | [diff] [blame] | 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. |
| 33 | * |
| 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 |
| 37 | * tests also belong in test-jq.js. Do not create any jQuery |
| 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: |
| 46 | * ++ test-nojq.js for "-gen js" only tests |
| 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 | |
| 54 | // all Languages in UTF-8 |
| 55 | 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 | 4f8a523 | 2011-09-09 08:17:02 +0000 | [diff] [blame] | 56 | |
| 57 | function checkRecursively(map1, map2) { |
| 58 | if (typeof map1 !== 'function' && typeof map2 !== 'function') { |
| 59 | if (!map1 || typeof map1 !== 'object') { |
Roger Meier | b661e83 | 2012-04-15 15:58:43 +0000 | [diff] [blame] | 60 | equal(map1, map2); |
Roger Meier | 4f8a523 | 2011-09-09 08:17:02 +0000 | [diff] [blame] | 61 | } else { |
| 62 | for (var key in map1) { |
| 63 | checkRecursively(map1[key], map2[key]); |
| 64 | } |
| 65 | } |
| 66 | } |
| 67 | } |
Roger Meier | bb267d4 | 2011-07-30 15:10:42 +0000 | [diff] [blame] | 68 | |
| 69 | module("Base Types"); |
| 70 | |
| 71 | test("Void", function() { |
Roger Meier | b661e83 | 2012-04-15 15:58:43 +0000 | [diff] [blame] | 72 | equal(client.testVoid(), undefined); |
Roger Meier | bb267d4 | 2011-07-30 15:10:42 +0000 | [diff] [blame] | 73 | }); |
| 74 | test("String", function() { |
Henrique Mendonca | 6af2ec0 | 2012-09-27 13:14:36 +0000 | [diff] [blame] | 75 | equal(client.testString(''), ''); |
Roger Meier | b661e83 | 2012-04-15 15:58:43 +0000 | [diff] [blame] | 76 | equal(client.testString(stringTest), stringTest); |
Roger Meier | bb267d4 | 2011-07-30 15:10:42 +0000 | [diff] [blame] | 77 | |
| 78 | var specialCharacters = 'quote: \" backslash:' + |
| 79 | ' forwardslash-escaped: \/ ' + |
| 80 | ' backspace: \b formfeed: \f newline: \n return: \r tab: ' + |
| 81 | ' now-all-of-them-together: "\\\/\b\n\r\t' + |
| 82 | ' now-a-bunch-of-junk: !@#$%&()(&%$#{}{}<><><'; |
Roger Meier | b661e83 | 2012-04-15 15:58:43 +0000 | [diff] [blame] | 83 | equal(client.testString(specialCharacters),specialCharacters); |
Roger Meier | bb267d4 | 2011-07-30 15:10:42 +0000 | [diff] [blame] | 84 | }); |
| 85 | test("Double", function() { |
Henrique Mendonca | 6af2ec0 | 2012-09-27 13:14:36 +0000 | [diff] [blame] | 86 | equal(client.testDouble(0), 0); |
| 87 | equal(client.testDouble(-1), -1); |
Roger Meier | b661e83 | 2012-04-15 15:58:43 +0000 | [diff] [blame] | 88 | equal(client.testDouble(3.14), 3.14); |
Henrique Mendonca | 6af2ec0 | 2012-09-27 13:14:36 +0000 | [diff] [blame] | 89 | equal(client.testDouble(Math.pow(2,60)), Math.pow(2,60)); |
Roger Meier | bb267d4 | 2011-07-30 15:10:42 +0000 | [diff] [blame] | 90 | }); |
| 91 | test("Byte", function() { |
Henrique Mendonca | 6af2ec0 | 2012-09-27 13:14:36 +0000 | [diff] [blame] | 92 | equal(client.testByte(0), 0); |
Roger Meier | b661e83 | 2012-04-15 15:58:43 +0000 | [diff] [blame] | 93 | equal(client.testByte(0x01), 0x01); |
Roger Meier | bb267d4 | 2011-07-30 15:10:42 +0000 | [diff] [blame] | 94 | }); |
| 95 | test("I32", function() { |
Henrique Mendonca | 6af2ec0 | 2012-09-27 13:14:36 +0000 | [diff] [blame] | 96 | equal(client.testI32(0), 0); |
Roger Meier | b661e83 | 2012-04-15 15:58:43 +0000 | [diff] [blame] | 97 | equal(client.testI32(Math.pow(2,30)), Math.pow(2,30)); |
Henrique Mendonca | 6af2ec0 | 2012-09-27 13:14:36 +0000 | [diff] [blame] | 98 | equal(client.testI32(-Math.pow(2,30)), -Math.pow(2,30)); |
Roger Meier | bb267d4 | 2011-07-30 15:10:42 +0000 | [diff] [blame] | 99 | }); |
| 100 | test("I64", function() { |
Henrique Mendonca | 6af2ec0 | 2012-09-27 13:14:36 +0000 | [diff] [blame] | 101 | equal(client.testI64(0), 0); |
henrique | a2de410 | 2014-02-07 14:12:56 +0100 | [diff] [blame] | 102 | //This is usually 2^60 but JS cannot represent anything over 2^52 accurately |
| 103 | equal(client.testI64(Math.pow(2,52)), Math.pow(2,52)); |
| 104 | equal(client.testI64(-Math.pow(2,52)), -Math.pow(2,52)); |
Roger Meier | bb267d4 | 2011-07-30 15:10:42 +0000 | [diff] [blame] | 105 | }); |
| 106 | |
| 107 | |
| 108 | module("Structured Types"); |
| 109 | |
| 110 | test("Struct", function() { |
Roger Meier | edf0d1d | 2011-08-03 21:21:43 +0000 | [diff] [blame] | 111 | var structTestInput = new ThriftTest.Xtruct(); |
| 112 | structTestInput.string_thing = 'worked'; |
| 113 | structTestInput.byte_thing = 0x01; |
| 114 | structTestInput.i32_thing = Math.pow(2,30); |
henrique | a2de410 | 2014-02-07 14:12:56 +0100 | [diff] [blame] | 115 | //This is usually 2^60 but JS cannot represent anything over 2^52 accurately |
| 116 | structTestInput.i64_thing = Math.pow(2,52); |
Roger Meier | bb267d4 | 2011-07-30 15:10:42 +0000 | [diff] [blame] | 117 | |
| 118 | var structTestOutput = client.testStruct(structTestInput); |
| 119 | |
Roger Meier | b661e83 | 2012-04-15 15:58:43 +0000 | [diff] [blame] | 120 | equal(structTestOutput.string_thing, structTestInput.string_thing); |
| 121 | equal(structTestOutput.byte_thing, structTestInput.byte_thing); |
| 122 | equal(structTestOutput.i32_thing, structTestInput.i32_thing); |
| 123 | equal(structTestOutput.i64_thing, structTestInput.i64_thing); |
Roger Meier | bb267d4 | 2011-07-30 15:10:42 +0000 | [diff] [blame] | 124 | |
Roger Meier | b661e83 | 2012-04-15 15:58:43 +0000 | [diff] [blame] | 125 | equal(JSON.stringify(structTestOutput), JSON.stringify(structTestInput)); |
Roger Meier | bb267d4 | 2011-07-30 15:10:42 +0000 | [diff] [blame] | 126 | }); |
| 127 | |
| 128 | test("Nest", function() { |
Roger Meier | edf0d1d | 2011-08-03 21:21:43 +0000 | [diff] [blame] | 129 | var xtrTestInput = new ThriftTest.Xtruct(); |
| 130 | xtrTestInput.string_thing = 'worked'; |
| 131 | xtrTestInput.byte_thing = 0x01; |
| 132 | xtrTestInput.i32_thing = Math.pow(2,30); |
henrique | a2de410 | 2014-02-07 14:12:56 +0100 | [diff] [blame] | 133 | //This is usually 2^60 but JS cannot represent anything over 2^52 accurately |
| 134 | xtrTestInput.i64_thing = Math.pow(2,52); |
Roger Meier | bb267d4 | 2011-07-30 15:10:42 +0000 | [diff] [blame] | 135 | |
Roger Meier | edf0d1d | 2011-08-03 21:21:43 +0000 | [diff] [blame] | 136 | var nestTestInput = new ThriftTest.Xtruct2(); |
| 137 | nestTestInput.byte_thing = 0x02; |
| 138 | nestTestInput.struct_thing = xtrTestInput; |
| 139 | nestTestInput.i32_thing = Math.pow(2,15); |
Roger Meier | bb267d4 | 2011-07-30 15:10:42 +0000 | [diff] [blame] | 140 | |
| 141 | var nestTestOutput = client.testNest(nestTestInput); |
| 142 | |
Roger Meier | b661e83 | 2012-04-15 15:58:43 +0000 | [diff] [blame] | 143 | equal(nestTestOutput.byte_thing, nestTestInput.byte_thing); |
| 144 | equal(nestTestOutput.struct_thing.string_thing, nestTestInput.struct_thing.string_thing); |
| 145 | equal(nestTestOutput.struct_thing.byte_thing, nestTestInput.struct_thing.byte_thing); |
| 146 | equal(nestTestOutput.struct_thing.i32_thing, nestTestInput.struct_thing.i32_thing); |
| 147 | equal(nestTestOutput.struct_thing.i64_thing, nestTestInput.struct_thing.i64_thing); |
| 148 | equal(nestTestOutput.i32_thing, nestTestInput.i32_thing); |
Roger Meier | bb267d4 | 2011-07-30 15:10:42 +0000 | [diff] [blame] | 149 | |
Roger Meier | b661e83 | 2012-04-15 15:58:43 +0000 | [diff] [blame] | 150 | equal(JSON.stringify(nestTestOutput), JSON.stringify(nestTestInput)); |
Roger Meier | bb267d4 | 2011-07-30 15:10:42 +0000 | [diff] [blame] | 151 | }); |
| 152 | |
| 153 | test("Map", function() { |
| 154 | var mapTestInput = {7:77, 8:88, 9:99}; |
| 155 | |
Roger Meier | edf0d1d | 2011-08-03 21:21:43 +0000 | [diff] [blame] | 156 | var mapTestOutput = client.testMap(mapTestInput); |
Roger Meier | bb267d4 | 2011-07-30 15:10:42 +0000 | [diff] [blame] | 157 | |
| 158 | for (var key in mapTestOutput) { |
Roger Meier | b661e83 | 2012-04-15 15:58:43 +0000 | [diff] [blame] | 159 | equal(mapTestOutput[key], mapTestInput[key]); |
Roger Meier | bb267d4 | 2011-07-30 15:10:42 +0000 | [diff] [blame] | 160 | } |
| 161 | }); |
| 162 | |
| 163 | test("StringMap", function() { |
| 164 | var mapTestInput = { |
| 165 | "a":"123", "a b":"with spaces ", "same":"same", "0":"numeric key", |
| 166 | "longValue":stringTest, stringTest:"long key" |
| 167 | }; |
| 168 | |
Roger Meier | edf0d1d | 2011-08-03 21:21:43 +0000 | [diff] [blame] | 169 | var mapTestOutput = client.testStringMap(mapTestInput); |
Roger Meier | bb267d4 | 2011-07-30 15:10:42 +0000 | [diff] [blame] | 170 | |
| 171 | for (var key in mapTestOutput) { |
Roger Meier | b661e83 | 2012-04-15 15:58:43 +0000 | [diff] [blame] | 172 | equal(mapTestOutput[key], mapTestInput[key]); |
Roger Meier | bb267d4 | 2011-07-30 15:10:42 +0000 | [diff] [blame] | 173 | } |
| 174 | }); |
| 175 | |
| 176 | test("Set", function() { |
Roger Meier | edf0d1d | 2011-08-03 21:21:43 +0000 | [diff] [blame] | 177 | var setTestInput = [1,2,3]; |
Roger Meier | bb267d4 | 2011-07-30 15:10:42 +0000 | [diff] [blame] | 178 | ok(client.testSet(setTestInput), setTestInput); |
| 179 | }); |
| 180 | |
| 181 | test("List", function() { |
Roger Meier | edf0d1d | 2011-08-03 21:21:43 +0000 | [diff] [blame] | 182 | var listTestInput = [1,2,3]; |
Roger Meier | bb267d4 | 2011-07-30 15:10:42 +0000 | [diff] [blame] | 183 | ok(client.testList(listTestInput), listTestInput); |
| 184 | }); |
| 185 | |
| 186 | test("Enum", function() { |
Roger Meier | b661e83 | 2012-04-15 15:58:43 +0000 | [diff] [blame] | 187 | equal(client.testEnum(ThriftTest.Numberz.ONE), ThriftTest.Numberz.ONE); |
Roger Meier | bb267d4 | 2011-07-30 15:10:42 +0000 | [diff] [blame] | 188 | }); |
| 189 | |
| 190 | test("TypeDef", function() { |
Roger Meier | b661e83 | 2012-04-15 15:58:43 +0000 | [diff] [blame] | 191 | equal(client.testTypedef(69), 69); |
Roger Meier | bb267d4 | 2011-07-30 15:10:42 +0000 | [diff] [blame] | 192 | }); |
| 193 | |
Jens Geyer | 329d59a | 2014-06-19 22:11:53 +0200 | [diff] [blame] | 194 | test("Skip", function() { |
| 195 | var structTestInput = new ThriftTest.Xtruct(); |
| 196 | var modifiedClient = new ThriftTest.ThriftTestClient(protocol); |
| 197 | |
| 198 | modifiedClient.recv_testStruct = function() { |
| 199 | var input = modifiedClient.input; |
| 200 | var xtruct3 = new ThriftTest.Xtruct3(); |
| 201 | |
| 202 | input.readMessageBegin(); |
| 203 | input.readStructBegin(); |
| 204 | |
| 205 | // read Xtruct data with Xtruct3 |
| 206 | input.readFieldBegin(); |
| 207 | xtruct3.read(input); |
| 208 | input.readFieldEnd(); |
| 209 | // read Thrift.Type.STOP message |
| 210 | input.readFieldBegin(); |
| 211 | input.readFieldEnd(); |
| 212 | |
| 213 | input.readStructEnd(); |
| 214 | input.readMessageEnd(); |
| 215 | |
| 216 | return xtruct3; |
| 217 | }; |
| 218 | |
| 219 | structTestInput.string_thing = 'worked'; |
| 220 | structTestInput.byte_thing = 0x01; |
| 221 | structTestInput.i32_thing = Math.pow(2,30); |
| 222 | structTestInput.i64_thing = Math.pow(2,52); |
| 223 | |
| 224 | var structTestOutput = modifiedClient.testStruct(structTestInput); |
| 225 | |
| 226 | equal(structTestOutput instanceof ThriftTest.Xtruct3, true); |
| 227 | equal(structTestOutput.string_thing, structTestInput.string_thing); |
| 228 | equal(structTestOutput.changed, null); |
| 229 | equal(structTestOutput.i32_thing, structTestInput.i32_thing); |
| 230 | equal(structTestOutput.i64_thing, structTestInput.i64_thing); |
| 231 | }); |
| 232 | |
Roger Meier | bb267d4 | 2011-07-30 15:10:42 +0000 | [diff] [blame] | 233 | |
| 234 | module("deeper!"); |
| 235 | |
| 236 | test("MapMap", function() { |
| 237 | var mapMapTestExpectedResult = { |
| 238 | "4":{"1":1,"2":2,"3":3,"4":4}, |
| 239 | "-4":{"-4":-4, "-3":-3, "-2":-2, "-1":-1} |
| 240 | }; |
| 241 | |
| 242 | var mapMapTestOutput = client.testMapMap(1); |
| 243 | |
| 244 | |
| 245 | for (var key in mapMapTestOutput) { |
| 246 | for (var key2 in mapMapTestOutput[key]) { |
Roger Meier | b661e83 | 2012-04-15 15:58:43 +0000 | [diff] [blame] | 247 | equal(mapMapTestOutput[key][key2], mapMapTestExpectedResult[key][key2]); |
Roger Meier | bb267d4 | 2011-07-30 15:10:42 +0000 | [diff] [blame] | 248 | } |
| 249 | } |
| 250 | |
Roger Meier | 4f8a523 | 2011-09-09 08:17:02 +0000 | [diff] [blame] | 251 | checkRecursively(mapMapTestOutput, mapMapTestExpectedResult); |
Roger Meier | bb267d4 | 2011-07-30 15:10:42 +0000 | [diff] [blame] | 252 | }); |
| 253 | |
| 254 | |
| 255 | module("Exception"); |
| 256 | |
| 257 | test("Xception", function() { |
| 258 | expect(2); |
| 259 | try{ |
| 260 | client.testException("Xception"); |
| 261 | }catch(e){ |
Roger Meier | b661e83 | 2012-04-15 15:58:43 +0000 | [diff] [blame] | 262 | equal(e.errorCode, 1001); |
| 263 | equal(e.message, "Xception"); |
Roger Meier | bb267d4 | 2011-07-30 15:10:42 +0000 | [diff] [blame] | 264 | } |
| 265 | }); |
| 266 | |
Roger Meier | b661e83 | 2012-04-15 15:58:43 +0000 | [diff] [blame] | 267 | test("no Exception", 0, function() { |
Roger Meier | bb267d4 | 2011-07-30 15:10:42 +0000 | [diff] [blame] | 268 | try{ |
| 269 | client.testException("no Exception"); |
| 270 | }catch(e){ |
| 271 | ok(false); |
| 272 | } |
| 273 | }); |
| 274 | |
Roger Meier | 8ebe0d9 | 2013-01-06 14:33:39 +0100 | [diff] [blame] | 275 | test("TException", function() { |
henrique | a2de410 | 2014-02-07 14:12:56 +0100 | [diff] [blame] | 276 | //ThriftTest does not list TException as a legal exception so it will |
| 277 | // generate an exception on the server that does not propagate back to |
| 278 | // the client. This test has been modified to equate to "no exception" |
Roger Meier | bb267d4 | 2011-07-30 15:10:42 +0000 | [diff] [blame] | 279 | expect(1); |
| 280 | try{ |
Roger Meier | 8ebe0d9 | 2013-01-06 14:33:39 +0100 | [diff] [blame] | 281 | client.testException("TException"); |
Roger Meier | bb267d4 | 2011-07-30 15:10:42 +0000 | [diff] [blame] | 282 | } catch(e) { |
henrique | a2de410 | 2014-02-07 14:12:56 +0100 | [diff] [blame] | 283 | //ok(false); |
Roger Meier | bb267d4 | 2011-07-30 15:10:42 +0000 | [diff] [blame] | 284 | } |
henrique | a2de410 | 2014-02-07 14:12:56 +0100 | [diff] [blame] | 285 | ok(true); |
Roger Meier | bb267d4 | 2011-07-30 15:10:42 +0000 | [diff] [blame] | 286 | }); |
| 287 | |
| 288 | |
| 289 | module("Insanity"); |
| 290 | |
| 291 | test("testInsanity", function() { |
| 292 | var insanity = { |
| 293 | "1":{ |
Roger Meier | 4f8a523 | 2011-09-09 08:17:02 +0000 | [diff] [blame] | 294 | "2":{ |
| 295 | "userMap":{ "5":5, "8":8 }, |
Roger Meier | bb267d4 | 2011-07-30 15:10:42 +0000 | [diff] [blame] | 296 | "xtructs":[{ |
| 297 | "string_thing":"Goodbye4", |
| 298 | "byte_thing":4, |
| 299 | "i32_thing":4, |
| 300 | "i64_thing":4 |
| 301 | }, |
| 302 | { |
| 303 | "string_thing":"Hello2", |
| 304 | "byte_thing":2, |
| 305 | "i32_thing":2, |
| 306 | "i64_thing":2 |
| 307 | } |
| 308 | ] |
| 309 | }, |
Roger Meier | 4f8a523 | 2011-09-09 08:17:02 +0000 | [diff] [blame] | 310 | "3":{ |
| 311 | "userMap":{ "5":5, "8":8 }, |
Roger Meier | bb267d4 | 2011-07-30 15:10:42 +0000 | [diff] [blame] | 312 | "xtructs":[{ |
| 313 | "string_thing":"Goodbye4", |
| 314 | "byte_thing":4, |
| 315 | "i32_thing":4, |
| 316 | "i64_thing":4 |
| 317 | }, |
| 318 | { |
| 319 | "string_thing":"Hello2", |
| 320 | "byte_thing":2, |
| 321 | "i32_thing":2, |
| 322 | "i64_thing":2 |
| 323 | } |
| 324 | ] |
| 325 | } |
| 326 | }, |
| 327 | "2":{ "6":{ "userMap":null, "xtructs":null } } |
| 328 | }; |
Roger Meier | b661e83 | 2012-04-15 15:58:43 +0000 | [diff] [blame] | 329 | var res = client.testInsanity(new ThriftTest.Insanity()); |
Roger Meier | bb267d4 | 2011-07-30 15:10:42 +0000 | [diff] [blame] | 330 | ok(res, JSON.stringify(res)); |
| 331 | ok(insanity, JSON.stringify(insanity)); |
Roger Meier | 4f8a523 | 2011-09-09 08:17:02 +0000 | [diff] [blame] | 332 | |
| 333 | checkRecursively(res, insanity); |
Roger Meier | bb267d4 | 2011-07-30 15:10:42 +0000 | [diff] [blame] | 334 | }); |
| 335 | |
| 336 | |
| 337 | ////////////////////////////////// |
| 338 | //Run same tests asynchronously |
Roger Meier | bb267d4 | 2011-07-30 15:10:42 +0000 | [diff] [blame] | 339 | |
| 340 | module("Async"); |
| 341 | |
| 342 | test("Double", function() { |
| 343 | expect( 1 ); |
| 344 | |
| 345 | QUnit.stop(); |
| 346 | client.testDouble(3.14159265, function(result) { |
Roger Meier | b661e83 | 2012-04-15 15:58:43 +0000 | [diff] [blame] | 347 | equal(result, 3.14159265); |
Roger Meier | bb267d4 | 2011-07-30 15:10:42 +0000 | [diff] [blame] | 348 | QUnit.start(); |
| 349 | }); |
| 350 | }); |
| 351 | |
| 352 | test("Byte", function() { |
| 353 | expect( 1 ); |
| 354 | |
| 355 | QUnit.stop(); |
| 356 | client.testByte(0x01, function(result) { |
Roger Meier | b661e83 | 2012-04-15 15:58:43 +0000 | [diff] [blame] | 357 | equal(result, 0x01); |
Roger Meier | bb267d4 | 2011-07-30 15:10:42 +0000 | [diff] [blame] | 358 | QUnit.start(); |
| 359 | }); |
| 360 | }); |
| 361 | |
| 362 | test("I32", function() { |
henrique | a2de410 | 2014-02-07 14:12:56 +0100 | [diff] [blame] | 363 | expect( 2 ); |
Roger Meier | bb267d4 | 2011-07-30 15:10:42 +0000 | [diff] [blame] | 364 | |
| 365 | QUnit.stop(); |
| 366 | client.testI32(Math.pow(2,30), function(result) { |
Roger Meier | b661e83 | 2012-04-15 15:58:43 +0000 | [diff] [blame] | 367 | equal(result, Math.pow(2,30)); |
Roger Meier | bb267d4 | 2011-07-30 15:10:42 +0000 | [diff] [blame] | 368 | QUnit.start(); |
| 369 | }); |
| 370 | |
| 371 | QUnit.stop(); |
henrique | a2de410 | 2014-02-07 14:12:56 +0100 | [diff] [blame] | 372 | client.testI32(Math.pow(-2,31), function(result) { |
Roger Meier | b661e83 | 2012-04-15 15:58:43 +0000 | [diff] [blame] | 373 | equal(result, Math.pow(-2,31)); |
Roger Meier | bb267d4 | 2011-07-30 15:10:42 +0000 | [diff] [blame] | 374 | QUnit.start(); |
| 375 | }); |
| 376 | }); |
| 377 | |
| 378 | test("I64", function() { |
Roger Meier | bb267d4 | 2011-07-30 15:10:42 +0000 | [diff] [blame] | 379 | expect( 2 ); |
| 380 | |
| 381 | QUnit.stop(); |
henrique | a2de410 | 2014-02-07 14:12:56 +0100 | [diff] [blame] | 382 | //This is usually 2^60 but JS cannot represent anything over 2^52 accurately |
| 383 | client.testI64(Math.pow(2,52), function(result) { |
| 384 | equal(result, Math.pow(2,52)); |
Roger Meier | bb267d4 | 2011-07-30 15:10:42 +0000 | [diff] [blame] | 385 | QUnit.start(); |
henrique | a2de410 | 2014-02-07 14:12:56 +0100 | [diff] [blame] | 386 | }); |
| 387 | |
| 388 | QUnit.stop(); |
| 389 | //This is usually 2^60 but JS cannot represent anything over 2^52 accurately |
| 390 | client.testI64(Math.pow(-2,52), function(result) { |
| 391 | equal(result, Math.pow(-2,52)); |
| 392 | QUnit.start(); |
Roger Meier | bb267d4 | 2011-07-30 15:10:42 +0000 | [diff] [blame] | 393 | }); |
| 394 | }); |