Roger Meier | edf0d1d | 2011-08-03 21:21:43 +0000 | [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 | */ |
| 19 | |
| 20 | |
| 21 | /* |
| 22 | * JavaScript test suite |
| 23 | */ |
| 24 | |
| 25 | var transport = new Thrift.Transport("/service"); |
| 26 | var protocol = new Thrift.Protocol(transport); |
| 27 | var client = new ThriftTest.ThriftTestClient(protocol); |
| 28 | |
| 29 | // all Languages in UTF-8 |
| 30 | 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] | 31 | |
| 32 | function checkRecursively(map1, map2) { |
| 33 | if (typeof map1 !== 'function' && typeof map2 !== 'function') { |
| 34 | if (!map1 || typeof map1 !== 'object') { |
Roger Meier | b661e83 | 2012-04-15 15:58:43 +0000 | [diff] [blame] | 35 | equal(map1, map2); |
Roger Meier | 4f8a523 | 2011-09-09 08:17:02 +0000 | [diff] [blame] | 36 | } else { |
| 37 | for (var key in map1) { |
| 38 | checkRecursively(map1[key], map2[key]); |
| 39 | } |
| 40 | } |
| 41 | } |
| 42 | } |
Roger Meier | bb267d4 | 2011-07-30 15:10:42 +0000 | [diff] [blame] | 43 | |
| 44 | module("Base Types"); |
| 45 | |
| 46 | test("Void", function() { |
Roger Meier | b661e83 | 2012-04-15 15:58:43 +0000 | [diff] [blame] | 47 | equal(client.testVoid(), undefined); |
Roger Meier | bb267d4 | 2011-07-30 15:10:42 +0000 | [diff] [blame] | 48 | }); |
| 49 | test("String", function() { |
Henrique Mendonca | 6af2ec0 | 2012-09-27 13:14:36 +0000 | [diff] [blame^] | 50 | equal(client.testString(''), ''); |
Roger Meier | b661e83 | 2012-04-15 15:58:43 +0000 | [diff] [blame] | 51 | equal(client.testString(stringTest), stringTest); |
Roger Meier | bb267d4 | 2011-07-30 15:10:42 +0000 | [diff] [blame] | 52 | |
| 53 | var specialCharacters = 'quote: \" backslash:' + |
| 54 | ' forwardslash-escaped: \/ ' + |
| 55 | ' backspace: \b formfeed: \f newline: \n return: \r tab: ' + |
| 56 | ' now-all-of-them-together: "\\\/\b\n\r\t' + |
| 57 | ' now-a-bunch-of-junk: !@#$%&()(&%$#{}{}<><><'; |
Roger Meier | b661e83 | 2012-04-15 15:58:43 +0000 | [diff] [blame] | 58 | equal(client.testString(specialCharacters),specialCharacters); |
Roger Meier | bb267d4 | 2011-07-30 15:10:42 +0000 | [diff] [blame] | 59 | }); |
| 60 | test("Double", function() { |
Henrique Mendonca | 6af2ec0 | 2012-09-27 13:14:36 +0000 | [diff] [blame^] | 61 | equal(client.testDouble(0), 0); |
| 62 | equal(client.testDouble(-1), -1); |
Roger Meier | b661e83 | 2012-04-15 15:58:43 +0000 | [diff] [blame] | 63 | equal(client.testDouble(3.14), 3.14); |
Henrique Mendonca | 6af2ec0 | 2012-09-27 13:14:36 +0000 | [diff] [blame^] | 64 | equal(client.testDouble(Math.pow(2,60)), Math.pow(2,60)); |
Roger Meier | bb267d4 | 2011-07-30 15:10:42 +0000 | [diff] [blame] | 65 | }); |
| 66 | test("Byte", function() { |
Henrique Mendonca | 6af2ec0 | 2012-09-27 13:14:36 +0000 | [diff] [blame^] | 67 | equal(client.testByte(0), 0); |
Roger Meier | b661e83 | 2012-04-15 15:58:43 +0000 | [diff] [blame] | 68 | equal(client.testByte(0x01), 0x01); |
Roger Meier | bb267d4 | 2011-07-30 15:10:42 +0000 | [diff] [blame] | 69 | }); |
| 70 | test("I32", function() { |
Henrique Mendonca | 6af2ec0 | 2012-09-27 13:14:36 +0000 | [diff] [blame^] | 71 | equal(client.testI32(0), 0); |
Roger Meier | b661e83 | 2012-04-15 15:58:43 +0000 | [diff] [blame] | 72 | equal(client.testI32(Math.pow(2,30)), Math.pow(2,30)); |
Henrique Mendonca | 6af2ec0 | 2012-09-27 13:14:36 +0000 | [diff] [blame^] | 73 | equal(client.testI32(-Math.pow(2,30)), -Math.pow(2,30)); |
Roger Meier | bb267d4 | 2011-07-30 15:10:42 +0000 | [diff] [blame] | 74 | }); |
| 75 | test("I64", function() { |
Henrique Mendonca | 6af2ec0 | 2012-09-27 13:14:36 +0000 | [diff] [blame^] | 76 | equal(client.testI64(0), 0); |
Roger Meier | b661e83 | 2012-04-15 15:58:43 +0000 | [diff] [blame] | 77 | equal(client.testI64(Math.pow(2,60)), Math.pow(2,60)); |
Henrique Mendonca | 6af2ec0 | 2012-09-27 13:14:36 +0000 | [diff] [blame^] | 78 | equal(client.testI64(-Math.pow(2,60)), -Math.pow(2,60)); |
Roger Meier | bb267d4 | 2011-07-30 15:10:42 +0000 | [diff] [blame] | 79 | }); |
| 80 | |
| 81 | |
| 82 | module("Structured Types"); |
| 83 | |
| 84 | test("Struct", function() { |
Roger Meier | edf0d1d | 2011-08-03 21:21:43 +0000 | [diff] [blame] | 85 | var structTestInput = new ThriftTest.Xtruct(); |
| 86 | structTestInput.string_thing = 'worked'; |
| 87 | structTestInput.byte_thing = 0x01; |
| 88 | structTestInput.i32_thing = Math.pow(2,30); |
| 89 | structTestInput.i64_thing = Math.pow(2,60); |
Roger Meier | bb267d4 | 2011-07-30 15:10:42 +0000 | [diff] [blame] | 90 | |
| 91 | var structTestOutput = client.testStruct(structTestInput); |
| 92 | |
Roger Meier | b661e83 | 2012-04-15 15:58:43 +0000 | [diff] [blame] | 93 | equal(structTestOutput.string_thing, structTestInput.string_thing); |
| 94 | equal(structTestOutput.byte_thing, structTestInput.byte_thing); |
| 95 | equal(structTestOutput.i32_thing, structTestInput.i32_thing); |
| 96 | equal(structTestOutput.i64_thing, structTestInput.i64_thing); |
Roger Meier | bb267d4 | 2011-07-30 15:10:42 +0000 | [diff] [blame] | 97 | |
Roger Meier | b661e83 | 2012-04-15 15:58:43 +0000 | [diff] [blame] | 98 | equal(JSON.stringify(structTestOutput), JSON.stringify(structTestInput)); |
Roger Meier | bb267d4 | 2011-07-30 15:10:42 +0000 | [diff] [blame] | 99 | }); |
| 100 | |
| 101 | test("Nest", function() { |
Roger Meier | edf0d1d | 2011-08-03 21:21:43 +0000 | [diff] [blame] | 102 | var xtrTestInput = new ThriftTest.Xtruct(); |
| 103 | xtrTestInput.string_thing = 'worked'; |
| 104 | xtrTestInput.byte_thing = 0x01; |
| 105 | xtrTestInput.i32_thing = Math.pow(2,30); |
| 106 | xtrTestInput.i64_thing = Math.pow(2,60); |
Roger Meier | bb267d4 | 2011-07-30 15:10:42 +0000 | [diff] [blame] | 107 | |
Roger Meier | edf0d1d | 2011-08-03 21:21:43 +0000 | [diff] [blame] | 108 | var nestTestInput = new ThriftTest.Xtruct2(); |
| 109 | nestTestInput.byte_thing = 0x02; |
| 110 | nestTestInput.struct_thing = xtrTestInput; |
| 111 | nestTestInput.i32_thing = Math.pow(2,15); |
Roger Meier | bb267d4 | 2011-07-30 15:10:42 +0000 | [diff] [blame] | 112 | |
| 113 | var nestTestOutput = client.testNest(nestTestInput); |
| 114 | |
Roger Meier | b661e83 | 2012-04-15 15:58:43 +0000 | [diff] [blame] | 115 | equal(nestTestOutput.byte_thing, nestTestInput.byte_thing); |
| 116 | equal(nestTestOutput.struct_thing.string_thing, nestTestInput.struct_thing.string_thing); |
| 117 | equal(nestTestOutput.struct_thing.byte_thing, nestTestInput.struct_thing.byte_thing); |
| 118 | equal(nestTestOutput.struct_thing.i32_thing, nestTestInput.struct_thing.i32_thing); |
| 119 | equal(nestTestOutput.struct_thing.i64_thing, nestTestInput.struct_thing.i64_thing); |
| 120 | equal(nestTestOutput.i32_thing, nestTestInput.i32_thing); |
Roger Meier | bb267d4 | 2011-07-30 15:10:42 +0000 | [diff] [blame] | 121 | |
Roger Meier | b661e83 | 2012-04-15 15:58:43 +0000 | [diff] [blame] | 122 | equal(JSON.stringify(nestTestOutput), JSON.stringify(nestTestInput)); |
Roger Meier | bb267d4 | 2011-07-30 15:10:42 +0000 | [diff] [blame] | 123 | }); |
| 124 | |
| 125 | test("Map", function() { |
| 126 | var mapTestInput = {7:77, 8:88, 9:99}; |
| 127 | |
Roger Meier | edf0d1d | 2011-08-03 21:21:43 +0000 | [diff] [blame] | 128 | var mapTestOutput = client.testMap(mapTestInput); |
Roger Meier | bb267d4 | 2011-07-30 15:10:42 +0000 | [diff] [blame] | 129 | |
| 130 | for (var key in mapTestOutput) { |
Roger Meier | b661e83 | 2012-04-15 15:58:43 +0000 | [diff] [blame] | 131 | equal(mapTestOutput[key], mapTestInput[key]); |
Roger Meier | bb267d4 | 2011-07-30 15:10:42 +0000 | [diff] [blame] | 132 | } |
| 133 | }); |
| 134 | |
| 135 | test("StringMap", function() { |
| 136 | var mapTestInput = { |
| 137 | "a":"123", "a b":"with spaces ", "same":"same", "0":"numeric key", |
| 138 | "longValue":stringTest, stringTest:"long key" |
| 139 | }; |
| 140 | |
Roger Meier | edf0d1d | 2011-08-03 21:21:43 +0000 | [diff] [blame] | 141 | var mapTestOutput = client.testStringMap(mapTestInput); |
Roger Meier | bb267d4 | 2011-07-30 15:10:42 +0000 | [diff] [blame] | 142 | |
| 143 | for (var key in mapTestOutput) { |
Roger Meier | b661e83 | 2012-04-15 15:58:43 +0000 | [diff] [blame] | 144 | equal(mapTestOutput[key], mapTestInput[key]); |
Roger Meier | bb267d4 | 2011-07-30 15:10:42 +0000 | [diff] [blame] | 145 | } |
| 146 | }); |
| 147 | |
| 148 | test("Set", function() { |
Roger Meier | edf0d1d | 2011-08-03 21:21:43 +0000 | [diff] [blame] | 149 | var setTestInput = [1,2,3]; |
Roger Meier | bb267d4 | 2011-07-30 15:10:42 +0000 | [diff] [blame] | 150 | ok(client.testSet(setTestInput), setTestInput); |
| 151 | }); |
| 152 | |
| 153 | test("List", function() { |
Roger Meier | edf0d1d | 2011-08-03 21:21:43 +0000 | [diff] [blame] | 154 | var listTestInput = [1,2,3]; |
Roger Meier | bb267d4 | 2011-07-30 15:10:42 +0000 | [diff] [blame] | 155 | ok(client.testList(listTestInput), listTestInput); |
| 156 | }); |
| 157 | |
| 158 | test("Enum", function() { |
Roger Meier | b661e83 | 2012-04-15 15:58:43 +0000 | [diff] [blame] | 159 | equal(client.testEnum(ThriftTest.Numberz.ONE), ThriftTest.Numberz.ONE); |
Roger Meier | bb267d4 | 2011-07-30 15:10:42 +0000 | [diff] [blame] | 160 | }); |
| 161 | |
| 162 | test("TypeDef", function() { |
Roger Meier | b661e83 | 2012-04-15 15:58:43 +0000 | [diff] [blame] | 163 | equal(client.testTypedef(69), 69); |
Roger Meier | bb267d4 | 2011-07-30 15:10:42 +0000 | [diff] [blame] | 164 | }); |
| 165 | |
| 166 | |
| 167 | module("deeper!"); |
| 168 | |
| 169 | test("MapMap", function() { |
| 170 | var mapMapTestExpectedResult = { |
| 171 | "4":{"1":1,"2":2,"3":3,"4":4}, |
| 172 | "-4":{"-4":-4, "-3":-3, "-2":-2, "-1":-1} |
| 173 | }; |
| 174 | |
| 175 | var mapMapTestOutput = client.testMapMap(1); |
| 176 | |
| 177 | |
| 178 | for (var key in mapMapTestOutput) { |
| 179 | for (var key2 in mapMapTestOutput[key]) { |
Roger Meier | b661e83 | 2012-04-15 15:58:43 +0000 | [diff] [blame] | 180 | equal(mapMapTestOutput[key][key2], mapMapTestExpectedResult[key][key2]); |
Roger Meier | bb267d4 | 2011-07-30 15:10:42 +0000 | [diff] [blame] | 181 | } |
| 182 | } |
| 183 | |
Roger Meier | 4f8a523 | 2011-09-09 08:17:02 +0000 | [diff] [blame] | 184 | checkRecursively(mapMapTestOutput, mapMapTestExpectedResult); |
Roger Meier | bb267d4 | 2011-07-30 15:10:42 +0000 | [diff] [blame] | 185 | }); |
| 186 | |
| 187 | |
| 188 | module("Exception"); |
| 189 | |
| 190 | test("Xception", function() { |
| 191 | expect(2); |
| 192 | try{ |
| 193 | client.testException("Xception"); |
| 194 | }catch(e){ |
Roger Meier | b661e83 | 2012-04-15 15:58:43 +0000 | [diff] [blame] | 195 | equal(e.errorCode, 1001); |
| 196 | equal(e.message, "Xception"); |
Roger Meier | bb267d4 | 2011-07-30 15:10:42 +0000 | [diff] [blame] | 197 | } |
| 198 | }); |
| 199 | |
Roger Meier | b661e83 | 2012-04-15 15:58:43 +0000 | [diff] [blame] | 200 | test("no Exception", 0, function() { |
Roger Meier | bb267d4 | 2011-07-30 15:10:42 +0000 | [diff] [blame] | 201 | try{ |
| 202 | client.testException("no Exception"); |
| 203 | }catch(e){ |
| 204 | ok(false); |
| 205 | } |
| 206 | }); |
| 207 | |
| 208 | test("unexpected Application Exception", function() { |
| 209 | expect(1); |
| 210 | try{ |
| 211 | client.testException("ApplicationException"); |
| 212 | } catch(e) { |
| 213 | ok(true); //@HACK: ignore faulty java server response for exceptions |
Roger Meier | b661e83 | 2012-04-15 15:58:43 +0000 | [diff] [blame] | 214 | //equal(e.message, "ApplicationException"); |
Roger Meier | bb267d4 | 2011-07-30 15:10:42 +0000 | [diff] [blame] | 215 | } |
| 216 | }); |
| 217 | |
| 218 | |
| 219 | module("Insanity"); |
| 220 | |
| 221 | test("testInsanity", function() { |
| 222 | var insanity = { |
| 223 | "1":{ |
Roger Meier | 4f8a523 | 2011-09-09 08:17:02 +0000 | [diff] [blame] | 224 | "2":{ |
| 225 | "userMap":{ "5":5, "8":8 }, |
Roger Meier | bb267d4 | 2011-07-30 15:10:42 +0000 | [diff] [blame] | 226 | "xtructs":[{ |
| 227 | "string_thing":"Goodbye4", |
| 228 | "byte_thing":4, |
| 229 | "i32_thing":4, |
| 230 | "i64_thing":4 |
| 231 | }, |
| 232 | { |
| 233 | "string_thing":"Hello2", |
| 234 | "byte_thing":2, |
| 235 | "i32_thing":2, |
| 236 | "i64_thing":2 |
| 237 | } |
| 238 | ] |
| 239 | }, |
Roger Meier | 4f8a523 | 2011-09-09 08:17:02 +0000 | [diff] [blame] | 240 | "3":{ |
| 241 | "userMap":{ "5":5, "8":8 }, |
Roger Meier | bb267d4 | 2011-07-30 15:10:42 +0000 | [diff] [blame] | 242 | "xtructs":[{ |
| 243 | "string_thing":"Goodbye4", |
| 244 | "byte_thing":4, |
| 245 | "i32_thing":4, |
| 246 | "i64_thing":4 |
| 247 | }, |
| 248 | { |
| 249 | "string_thing":"Hello2", |
| 250 | "byte_thing":2, |
| 251 | "i32_thing":2, |
| 252 | "i64_thing":2 |
| 253 | } |
| 254 | ] |
| 255 | } |
| 256 | }, |
| 257 | "2":{ "6":{ "userMap":null, "xtructs":null } } |
| 258 | }; |
Roger Meier | b661e83 | 2012-04-15 15:58:43 +0000 | [diff] [blame] | 259 | var res = client.testInsanity(new ThriftTest.Insanity()); |
Roger Meier | bb267d4 | 2011-07-30 15:10:42 +0000 | [diff] [blame] | 260 | ok(res, JSON.stringify(res)); |
| 261 | ok(insanity, JSON.stringify(insanity)); |
Roger Meier | 4f8a523 | 2011-09-09 08:17:02 +0000 | [diff] [blame] | 262 | |
| 263 | checkRecursively(res, insanity); |
Roger Meier | bb267d4 | 2011-07-30 15:10:42 +0000 | [diff] [blame] | 264 | }); |
| 265 | |
| 266 | |
| 267 | ////////////////////////////////// |
| 268 | //Run same tests asynchronously |
| 269 | jQuery.ajaxSetup({ timeout: 0 }); |
| 270 | $(document).ajaxError( function() { QUnit.start(); } ); |
| 271 | |
| 272 | module("Async Manual"); |
| 273 | |
| 274 | test("testI32", function() { |
| 275 | expect( 2 ); |
| 276 | QUnit.stop(); |
| 277 | |
| 278 | var transport = new Thrift.Transport(); |
| 279 | var protocol = new Thrift.Protocol(transport); |
| 280 | var client = new ThriftTest.ThriftTestClient(protocol); |
| 281 | |
| 282 | var jqxhr = jQuery.ajax({ |
| 283 | url: "/service", |
| 284 | data: client.send_testI32(Math.pow(-2,31)), |
| 285 | type: "POST", |
| 286 | cache: false, |
| 287 | dataType: "text", |
| 288 | success: function(res){ |
| 289 | transport.setRecvBuffer( res ); |
Roger Meier | b661e83 | 2012-04-15 15:58:43 +0000 | [diff] [blame] | 290 | equal(client.recv_testI32(), Math.pow(-2,31)); |
Roger Meier | bb267d4 | 2011-07-30 15:10:42 +0000 | [diff] [blame] | 291 | }, |
| 292 | error: function() { ok(false); }, |
| 293 | complete: function() { |
| 294 | ok(true); |
| 295 | QUnit.start(); |
| 296 | } |
| 297 | }); |
| 298 | }); |
| 299 | |
| 300 | |
| 301 | test("testI64", function() { |
| 302 | expect( 2 ); |
| 303 | QUnit.stop(); |
| 304 | |
| 305 | var transport = new Thrift.Transport(); |
| 306 | var protocol = new Thrift.Protocol(transport); |
| 307 | var client = new ThriftTest.ThriftTestClient(protocol); |
| 308 | |
| 309 | jQuery.ajax({ |
| 310 | url: "/service", |
| 311 | data: client.send_testI64(Math.pow(-2,61)), |
| 312 | type: "POST", |
| 313 | cache: false, |
| 314 | dataType: "text", |
| 315 | success: function(res){ |
| 316 | transport.setRecvBuffer( res ); |
Roger Meier | b661e83 | 2012-04-15 15:58:43 +0000 | [diff] [blame] | 317 | equal(client.recv_testI64(), Math.pow(-2,61)); |
Roger Meier | bb267d4 | 2011-07-30 15:10:42 +0000 | [diff] [blame] | 318 | }, |
| 319 | error: function() { ok(false); }, |
| 320 | complete: function() { |
| 321 | ok(true); |
| 322 | QUnit.start(); |
| 323 | } |
| 324 | }); |
| 325 | }); |
| 326 | |
| 327 | |
| 328 | module("Async"); |
| 329 | |
| 330 | test("Double", function() { |
| 331 | expect( 1 ); |
| 332 | |
| 333 | QUnit.stop(); |
| 334 | client.testDouble(3.14159265, function(result) { |
Roger Meier | b661e83 | 2012-04-15 15:58:43 +0000 | [diff] [blame] | 335 | equal(result, 3.14159265); |
Roger Meier | bb267d4 | 2011-07-30 15:10:42 +0000 | [diff] [blame] | 336 | QUnit.start(); |
| 337 | }); |
| 338 | }); |
| 339 | |
| 340 | test("Byte", function() { |
| 341 | expect( 1 ); |
| 342 | |
| 343 | QUnit.stop(); |
| 344 | client.testByte(0x01, function(result) { |
Roger Meier | b661e83 | 2012-04-15 15:58:43 +0000 | [diff] [blame] | 345 | equal(result, 0x01); |
Roger Meier | bb267d4 | 2011-07-30 15:10:42 +0000 | [diff] [blame] | 346 | QUnit.start(); |
| 347 | }); |
| 348 | }); |
| 349 | |
| 350 | test("I32", function() { |
| 351 | expect( 3 ); |
| 352 | |
| 353 | QUnit.stop(); |
| 354 | client.testI32(Math.pow(2,30), function(result) { |
Roger Meier | b661e83 | 2012-04-15 15:58:43 +0000 | [diff] [blame] | 355 | equal(result, Math.pow(2,30)); |
Roger Meier | bb267d4 | 2011-07-30 15:10:42 +0000 | [diff] [blame] | 356 | QUnit.start(); |
| 357 | }); |
| 358 | |
| 359 | QUnit.stop(); |
| 360 | var jqxhr = client.testI32(Math.pow(-2,31), function(result) { |
Roger Meier | b661e83 | 2012-04-15 15:58:43 +0000 | [diff] [blame] | 361 | equal(result, Math.pow(-2,31)); |
Roger Meier | bb267d4 | 2011-07-30 15:10:42 +0000 | [diff] [blame] | 362 | }); |
| 363 | |
| 364 | jqxhr.success(function(result) { |
Roger Meier | b661e83 | 2012-04-15 15:58:43 +0000 | [diff] [blame] | 365 | equal(result, Math.pow(-2,31)); |
Roger Meier | bb267d4 | 2011-07-30 15:10:42 +0000 | [diff] [blame] | 366 | QUnit.start(); |
| 367 | }); |
| 368 | }); |
| 369 | |
| 370 | test("I64", function() { |
| 371 | expect( 4 ); |
| 372 | |
| 373 | QUnit.stop(); |
| 374 | client.testI64(Math.pow(2,60), function(result) { |
Roger Meier | b661e83 | 2012-04-15 15:58:43 +0000 | [diff] [blame] | 375 | equal(result, Math.pow(2,60)); |
Roger Meier | bb267d4 | 2011-07-30 15:10:42 +0000 | [diff] [blame] | 376 | QUnit.start(); |
| 377 | }); |
| 378 | |
| 379 | QUnit.stop(); |
| 380 | client.testI64(Math.pow(-2,61), function(result) { |
Roger Meier | b661e83 | 2012-04-15 15:58:43 +0000 | [diff] [blame] | 381 | equal(result, Math.pow(-2,61)); |
Roger Meier | bb267d4 | 2011-07-30 15:10:42 +0000 | [diff] [blame] | 382 | }) |
Henrique Mendonca | 6af2ec0 | 2012-09-27 13:14:36 +0000 | [diff] [blame^] | 383 | .error( function(xhr, status, e) { ok(false, e.message); } ) |
Roger Meier | bb267d4 | 2011-07-30 15:10:42 +0000 | [diff] [blame] | 384 | .success(function(result) { |
Roger Meier | b661e83 | 2012-04-15 15:58:43 +0000 | [diff] [blame] | 385 | equal(result, Math.pow(-2,61)); |
Roger Meier | bb267d4 | 2011-07-30 15:10:42 +0000 | [diff] [blame] | 386 | }) |
| 387 | .complete(function() { |
| 388 | ok(true); |
| 389 | QUnit.start(); |
| 390 | }); |
| 391 | }); |
| 392 | |
| 393 | test("Xception", function() { |
| 394 | expect( 2 ); |
| 395 | |
| 396 | QUnit.stop(); |
| 397 | |
| 398 | var dfd = client.testException("Xception", function(result) { |
| 399 | ok(false); |
| 400 | QUnit.start(); |
| 401 | }) |
Henrique Mendonca | 6af2ec0 | 2012-09-27 13:14:36 +0000 | [diff] [blame^] | 402 | .error(function(xhr, status, e){ |
Roger Meier | b661e83 | 2012-04-15 15:58:43 +0000 | [diff] [blame] | 403 | equal(e.errorCode, 1001); |
| 404 | equal(e.message, "Xception"); |
Roger Meier | bb267d4 | 2011-07-30 15:10:42 +0000 | [diff] [blame] | 405 | QUnit.start(); |
| 406 | }); |
| 407 | }); |