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