| Roger Meier | b3b07d6 | 2011-02-22 20:55:21 +0000 | [diff] [blame] | 1 | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> | 
| Bryan Duxbury | 3ff373e | 2010-08-15 23:19:06 +0000 | [diff] [blame] | 2 | <!-- | 
 | 3 |   Licensed to the Apache Software Foundation (ASF) under one | 
 | 4 |   or more contributor license agreements. See the NOTICE file | 
 | 5 |   distributed with this work for additional information | 
 | 6 |   regarding copyright ownership. The ASF licenses this file | 
 | 7 |   to you under the Apache License, Version 2.0 (the | 
 | 8 |   "License"); you may not use this file except in compliance | 
 | 9 |   with the License. You may obtain a copy of the License at | 
 | 10 |  | 
 | 11 |     http://www.apache.org/licenses/LICENSE-2.0 | 
 | 12 |  | 
 | 13 |   Unless required by applicable law or agreed to in writing, | 
 | 14 |   software distributed under the License is distributed on an | 
 | 15 |   "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | 
 | 16 |   KIND, either express or implied. See the License for the | 
 | 17 |   specific language governing permissions and limitations | 
 | 18 |   under the License. | 
 | 19 | --> | 
| T Jake Luciani | efabb89 | 2010-07-28 22:31:12 +0000 | [diff] [blame] | 20 | <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> | 
| T Jake Luciani | 322caa2 | 2010-02-15 03:24:55 +0000 | [diff] [blame] | 21 | <head> | 
| T Jake Luciani | efabb89 | 2010-07-28 22:31:12 +0000 | [diff] [blame] | 22 |   <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> | 
 | 23 |   <title>Thrift Javascript Bindings: Unit Test</title> | 
| T Jake Luciani | 322caa2 | 2010-02-15 03:24:55 +0000 | [diff] [blame] | 24 |  | 
| T Jake Luciani | efabb89 | 2010-07-28 22:31:12 +0000 | [diff] [blame] | 25 |   <script src="/thrift.js"                  type="text/javascript" charset="utf-8"></script> | 
 | 26 |   <script src="gen-js/ThriftTest_types.js" type="text/javascript" charset="utf-8"></script> | 
 | 27 |   <script src="gen-js/ThriftTest.js"       type="text/javascript" charset="utf-8"></script> | 
| T Jake Luciani | 322caa2 | 2010-02-15 03:24:55 +0000 | [diff] [blame] | 28 |  | 
| T Jake Luciani | efabb89 | 2010-07-28 22:31:12 +0000 | [diff] [blame] | 29 |   <!-- jQuery --> | 
| Roger Meier | 08b3099 | 2011-04-06 21:30:53 +0000 | [diff] [blame] | 30 |   <script type="text/javascript" src="http://code.jquery.com/jquery-1.5.2.js" charset="utf-8"></script> | 
| Bryan Duxbury | 3ff373e | 2010-08-15 23:19:06 +0000 | [diff] [blame] | 31 |    | 
 | 32 |   <!-- json2  --> | 
 | 33 |   <script type="text/javascript" src="json2.js" charset="utf-8"></script> | 
| T Jake Luciani | efabb89 | 2010-07-28 22:31:12 +0000 | [diff] [blame] | 34 |  | 
 | 35 |   <!-- QUnit Test framework--> | 
| Roger Meier | 5860f88 | 2011-05-22 09:59:34 +0000 | [diff] [blame] | 36 |   <script type="text/javascript" src="http://code.jquery.com/qunit/git/qunit.js" charset="utf-8"></script> | 
 | 37 |   <link rel="stylesheet" href="http://code.jquery.com/qunit/git/qunit.css" type="text/css" media="screen" /> | 
| T Jake Luciani | efabb89 | 2010-07-28 22:31:12 +0000 | [diff] [blame] | 38 |  | 
 | 39 |   <script type="text/javascript" charset="utf-8"> | 
 | 40 |   //<![CDATA[ | 
 | 41 |   $(document).ready(function(){ | 
| Roger Meier | 08b3099 | 2011-04-06 21:30:53 +0000 | [diff] [blame] | 42 |     var transport = new Thrift.Transport("/service"); | 
 | 43 |     var protocol  = new Thrift.Protocol(transport); | 
 | 44 |     var client    = new ThriftTest.ThriftTestClient(protocol); | 
| T Jake Luciani | efabb89 | 2010-07-28 22:31:12 +0000 | [diff] [blame] | 45 |  | 
| Roger Meier | 9d8e8f8 | 2011-06-14 19:38:27 +0000 | [diff] [blame] | 46 |     // all Languages in UTF-8 | 
 | 47 |     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ú, 粵語"; | 
 | 48 |  | 
| T Jake Luciani | efabb89 | 2010-07-28 22:31:12 +0000 | [diff] [blame] | 49 |  | 
 | 50 |     module("Base Types"); | 
| Roger Meier | 9d8e8f8 | 2011-06-14 19:38:27 +0000 | [diff] [blame] | 51 |  | 
| Bryan Duxbury | 3ff373e | 2010-08-15 23:19:06 +0000 | [diff] [blame] | 52 |     test("Void", function() { | 
 | 53 |       equals(client.testVoid(), undefined); | 
| T Jake Luciani | efabb89 | 2010-07-28 22:31:12 +0000 | [diff] [blame] | 54 |     }); | 
| Bryan Duxbury | 3ff373e | 2010-08-15 23:19:06 +0000 | [diff] [blame] | 55 |     test("String", function() { | 
| Bryan Duxbury | 3ff373e | 2010-08-15 23:19:06 +0000 | [diff] [blame] | 56 |       equals(client.testString(stringTest), stringTest); | 
| Roger Meier | c991270 | 2010-10-15 13:16:05 +0000 | [diff] [blame] | 57 |  | 
 | 58 |       var specialCharacters = 'quote: \" backslash:' + | 
 | 59 |             ' forwardslash-escaped: \/ ' + | 
 | 60 |             ' backspace: \b formfeed: \f newline: \n return: \r tab: ' + | 
 | 61 |             ' now-all-of-them-together: "\\\/\b\n\r\t' + | 
 | 62 |             ' now-a-bunch-of-junk: !@#$%&()(&%$#{}{}<><><'; | 
 | 63 |       equals(client.testString(specialCharacters),specialCharacters); | 
| T Jake Luciani | efabb89 | 2010-07-28 22:31:12 +0000 | [diff] [blame] | 64 |     }); | 
 | 65 |     test("Double", function() { | 
 | 66 |       equals(client.testDouble(3.14), 3.14); | 
 | 67 |     }); | 
 | 68 |     test("Byte", function() { | 
 | 69 |       equals(client.testByte(0x01), 0x01); | 
 | 70 |     }); | 
 | 71 |     test("I32", function() { | 
 | 72 |       equals(client.testI32(Math.pow(2,30)), Math.pow(2,30)); | 
 | 73 |     }); | 
 | 74 |     test("I64", function() { | 
 | 75 |       equals(client.testI64(Math.pow(2,60)), Math.pow(2,60)); | 
 | 76 |     }); | 
 | 77 |  | 
 | 78 |  | 
 | 79 |     module("Structured Types"); | 
 | 80 |  | 
| T Jake Luciani | efabb89 | 2010-07-28 22:31:12 +0000 | [diff] [blame] | 81 |     test("Struct", function() { | 
| Bryan Duxbury | 3ff373e | 2010-08-15 23:19:06 +0000 | [diff] [blame] | 82 |       var structTestInput = new ThriftTest.Xtruct() | 
 | 83 |       structTestInput.string_thing = 'worked' | 
 | 84 |       structTestInput.byte_thing = 0x01 | 
 | 85 |       structTestInput.i32_thing = Math.pow(2,30) | 
 | 86 |       structTestInput.i64_thing = Math.pow(2,60) | 
 | 87 |  | 
 | 88 |       var structTestOutput = client.testStruct(structTestInput); | 
 | 89 |  | 
 | 90 |       equals(structTestOutput.string_thing, structTestInput.string_thing); | 
 | 91 |       equals(structTestOutput.byte_thing, structTestInput.byte_thing); | 
 | 92 |       equals(structTestOutput.i32_thing, structTestInput.i32_thing); | 
 | 93 |       equals(structTestOutput.i64_thing, structTestInput.i64_thing); | 
 | 94 |        | 
 | 95 |       equals(JSON.stringify(structTestOutput), JSON.stringify(structTestInput)) | 
| T Jake Luciani | efabb89 | 2010-07-28 22:31:12 +0000 | [diff] [blame] | 96 |     }); | 
| Bryan Duxbury | 3ff373e | 2010-08-15 23:19:06 +0000 | [diff] [blame] | 97 |      | 
| T Jake Luciani | efabb89 | 2010-07-28 22:31:12 +0000 | [diff] [blame] | 98 |     test("Nest", function() { | 
| Bryan Duxbury | 3ff373e | 2010-08-15 23:19:06 +0000 | [diff] [blame] | 99 |       var xtrTestInput = new ThriftTest.Xtruct() | 
 | 100 |       xtrTestInput.string_thing = 'worked' | 
 | 101 |       xtrTestInput.byte_thing = 0x01 | 
 | 102 |       xtrTestInput.i32_thing = Math.pow(2,30) | 
 | 103 |       xtrTestInput.i64_thing = Math.pow(2,60) | 
 | 104 |        | 
 | 105 |       var nestTestInput = new ThriftTest.Xtruct2() | 
 | 106 |       nestTestInput.byte_thing = 0x02 | 
 | 107 |       nestTestInput.struct_thing = xtrTestInput | 
 | 108 |       nestTestInput.i32_thing = Math.pow(2,15) | 
 | 109 |        | 
 | 110 |       var nestTestOutput = client.testNest(nestTestInput); | 
 | 111 |        | 
 | 112 |       equals(nestTestOutput.byte_thing, nestTestInput.byte_thing); | 
 | 113 |       equals(nestTestOutput.struct_thing.string_thing, nestTestInput.struct_thing.string_thing); | 
 | 114 |       equals(nestTestOutput.struct_thing.byte_thing, nestTestInput.struct_thing.byte_thing); | 
 | 115 |       equals(nestTestOutput.struct_thing.i32_thing, nestTestInput.struct_thing.i32_thing); | 
 | 116 |       equals(nestTestOutput.struct_thing.i64_thing, nestTestInput.struct_thing.i64_thing); | 
 | 117 |       equals(nestTestOutput.i32_thing, nestTestInput.i32_thing); | 
 | 118 |        | 
 | 119 |       equals(JSON.stringify(nestTestOutput), JSON.stringify(nestTestInput)) | 
| T Jake Luciani | efabb89 | 2010-07-28 22:31:12 +0000 | [diff] [blame] | 120 |     }); | 
| Roger Meier | 9d8e8f8 | 2011-06-14 19:38:27 +0000 | [diff] [blame] | 121 |  | 
| T Jake Luciani | efabb89 | 2010-07-28 22:31:12 +0000 | [diff] [blame] | 122 |     test("Map", function() { | 
| Bryan Duxbury | 3ff373e | 2010-08-15 23:19:06 +0000 | [diff] [blame] | 123 |       var mapTestInput = {7:77, 8:88, 9:99}; | 
 | 124 |  | 
 | 125 |       var mapTestOutput = client.testMap(mapTestInput) | 
| Roger Meier | 9d8e8f8 | 2011-06-14 19:38:27 +0000 | [diff] [blame] | 126 |  | 
| Bryan Duxbury | 3ff373e | 2010-08-15 23:19:06 +0000 | [diff] [blame] | 127 |       for (var key in mapTestOutput) { | 
 | 128 |         equals(mapTestOutput[key], mapTestInput[key]); | 
 | 129 |       } | 
| T Jake Luciani | efabb89 | 2010-07-28 22:31:12 +0000 | [diff] [blame] | 130 |     }); | 
| Roger Meier | 9d8e8f8 | 2011-06-14 19:38:27 +0000 | [diff] [blame] | 131 |  | 
 | 132 |     test("StringMap", function() { | 
 | 133 |       var mapTestInput = { | 
 | 134 |         "a":"123", "a b":"with spaces ", "same":"same", "0":"numeric key", | 
 | 135 |         "longValue":stringTest, stringTest:"long key" | 
 | 136 |       }; | 
 | 137 |  | 
 | 138 |       var mapTestOutput = client.testStringMap(mapTestInput) | 
 | 139 |  | 
 | 140 |       for (var key in mapTestOutput) { | 
 | 141 |         equals(mapTestOutput[key], mapTestInput[key]); | 
 | 142 |       } | 
 | 143 |     }); | 
 | 144 |  | 
| T Jake Luciani | efabb89 | 2010-07-28 22:31:12 +0000 | [diff] [blame] | 145 |     test("Set", function() { | 
| Bryan Duxbury | 3ff373e | 2010-08-15 23:19:06 +0000 | [diff] [blame] | 146 |       var setTestInput = new Array(1,2,3) | 
 | 147 |       ok(client.testSet(setTestInput), setTestInput); | 
| T Jake Luciani | efabb89 | 2010-07-28 22:31:12 +0000 | [diff] [blame] | 148 |     }); | 
| Bryan Duxbury | 3ff373e | 2010-08-15 23:19:06 +0000 | [diff] [blame] | 149 |      | 
 | 150 |     test("List", function() { | 
 | 151 |       var listTestInput = new Array(1,2,3) | 
 | 152 |       ok(client.testList(listTestInput), listTestInput); | 
 | 153 |     }); | 
 | 154 |      | 
| T Jake Luciani | efabb89 | 2010-07-28 22:31:12 +0000 | [diff] [blame] | 155 |     test("Enum", function() { | 
 | 156 |       equals(client.testEnum(ThriftTest.Numberz.ONE), ThriftTest.Numberz.ONE); | 
 | 157 |     }); | 
| Bryan Duxbury | 3ff373e | 2010-08-15 23:19:06 +0000 | [diff] [blame] | 158 |      | 
 | 159 |     test("TypeDef", function() { | 
 | 160 |       equals(client.testTypedef(69), 69); | 
 | 161 |     }); | 
 | 162 |  | 
 | 163 |     module("deeper!"); | 
 | 164 |      | 
 | 165 |     test("MapMap", function() { | 
 | 166 |       var mapMapTestExpectedResult = { | 
| Roger Meier | d992498 | 2011-02-24 16:04:03 +0000 | [diff] [blame] | 167 |         "4":{"1":1,"2":2,"3":3,"4":4}, | 
 | 168 |         "-4":{"-4":-4, "-3":-3, "-2":-2, "-1":-1} | 
| Bryan Duxbury | 3ff373e | 2010-08-15 23:19:06 +0000 | [diff] [blame] | 169 |       }; | 
 | 170 |  | 
 | 171 |       var mapMapTestOutput = client.testMapMap(1); | 
| Roger Meier | d992498 | 2011-02-24 16:04:03 +0000 | [diff] [blame] | 172 |  | 
 | 173 |  | 
 | 174 |       for (var key in mapMapTestOutput) { | 
 | 175 |         for (var key2 in mapMapTestOutput[key]) { | 
 | 176 |           equals(mapMapTestOutput[key][key2], mapMapTestExpectedResult[key][key2]); | 
 | 177 |         } | 
 | 178 |       } | 
| Bryan Duxbury | 3ff373e | 2010-08-15 23:19:06 +0000 | [diff] [blame] | 179 |        | 
 | 180 |       equals(JSON.stringify(mapMapTestOutput), JSON.stringify(mapMapTestExpectedResult)) | 
 | 181 |     }); | 
| Bryan Duxbury | 3ff373e | 2010-08-15 23:19:06 +0000 | [diff] [blame] | 182 |  | 
| T Jake Luciani | efabb89 | 2010-07-28 22:31:12 +0000 | [diff] [blame] | 183 |  | 
 | 184 |     module("Exception"); | 
 | 185 |  | 
 | 186 |     test("Xception", function() { | 
 | 187 |       expect(2); | 
 | 188 |       try{ | 
 | 189 |         client.testException("Xception"); | 
 | 190 |       }catch(e){ | 
| Roger Meier | 37b5bf8 | 2010-10-24 21:41:24 +0000 | [diff] [blame] | 191 |         equals(e.errorCode, 1001); | 
| Roger Meier | d992498 | 2011-02-24 16:04:03 +0000 | [diff] [blame] | 192 |         equals(e.message, "Xception"); | 
| T Jake Luciani | efabb89 | 2010-07-28 22:31:12 +0000 | [diff] [blame] | 193 |       } | 
 | 194 |     }); | 
 | 195 |  | 
 | 196 |     test("no Exception", function() { | 
| T Jake Luciani | efabb89 | 2010-07-28 22:31:12 +0000 | [diff] [blame] | 197 |       try{ | 
 | 198 |         client.testException("no Exception"); | 
 | 199 |       }catch(e){ | 
| Roger Meier | b3b07d6 | 2011-02-22 20:55:21 +0000 | [diff] [blame] | 200 |         ok(false); | 
 | 201 |       } | 
 | 202 |     }); | 
 | 203 |  | 
 | 204 |     test("unexpected Application Exception", function() { | 
 | 205 |       expect(1); | 
 | 206 |       try{ | 
 | 207 |         client.testException("ApplicationException"); | 
 | 208 |       } catch(e) { | 
| Roger Meier | d992498 | 2011-02-24 16:04:03 +0000 | [diff] [blame] | 209 |         ok(true); //@HACK: ignore faulty java server response for exceptions | 
| Roger Meier | 08b3099 | 2011-04-06 21:30:53 +0000 | [diff] [blame] | 210 |         //equals(e.message, "ApplicationException"); | 
| T Jake Luciani | efabb89 | 2010-07-28 22:31:12 +0000 | [diff] [blame] | 211 |       } | 
 | 212 |     }); | 
 | 213 |  | 
 | 214 |  | 
 | 215 |     module("Insanity"); | 
 | 216 |  | 
 | 217 |     test("testInsanity", function() { | 
| Roger Meier | a35944b | 2011-07-15 20:16:43 +0000 | [diff] [blame] | 218 |       var insanity = { | 
 | 219 |         "1":{ | 
 | 220 |           "3":{ | 
 | 221 |             "userMap":{ "8":8, "5":5 }, | 
 | 222 |             "xtructs":[{ | 
 | 223 |                 "string_thing":"Goodbye4", | 
 | 224 |                 "byte_thing":4, | 
 | 225 |                 "i32_thing":4, | 
 | 226 |                 "i64_thing":4 | 
 | 227 |               }, | 
 | 228 |               { | 
 | 229 |                 "string_thing":"Hello2", | 
 | 230 |                 "byte_thing":2, | 
 | 231 |                 "i32_thing":2, | 
 | 232 |                 "i64_thing":2 | 
 | 233 |               } | 
 | 234 |             ] | 
 | 235 |           }, | 
 | 236 |           "2":{ | 
 | 237 |             "userMap":{ "8":8, "5":5 }, | 
 | 238 |             "xtructs":[{ | 
 | 239 |                 "string_thing":"Goodbye4", | 
 | 240 |                 "byte_thing":4, | 
 | 241 |                 "i32_thing":4, | 
 | 242 |                 "i64_thing":4 | 
 | 243 |               }, | 
 | 244 |               { | 
 | 245 |                 "string_thing":"Hello2", | 
 | 246 |                 "byte_thing":2, | 
 | 247 |                 "i32_thing":2, | 
 | 248 |                 "i64_thing":2 | 
 | 249 |               } | 
 | 250 |             ] | 
 | 251 |           } | 
 | 252 |         }, | 
 | 253 |         "2":{ "6":{ "userMap":null, "xtructs":null } } | 
 | 254 |       }; | 
 | 255 |       var res = client.testInsanity(""); | 
 | 256 |       ok(res, JSON.stringify(res)); | 
 | 257 |       ok(insanity, JSON.stringify(insanity)); | 
 | 258 |       equals(JSON.stringify(res), JSON.stringify(insanity)) //TODO: read and compare maps recursively | 
| T Jake Luciani | efabb89 | 2010-07-28 22:31:12 +0000 | [diff] [blame] | 259 |     }); | 
 | 260 |  | 
| Roger Meier | 08b3099 | 2011-04-06 21:30:53 +0000 | [diff] [blame] | 261 |  | 
 | 262 |     ////////////////////////////////// | 
 | 263 |     //Run same tests asynchronously | 
 | 264 |     jQuery.ajaxSetup({ timeout: 0 }); | 
 | 265 |     $(document).ajaxError( function() { QUnit.start(); } ); | 
 | 266 |  | 
 | 267 |     module("Async Manual"); | 
 | 268 |  | 
 | 269 |     test("testI32", function() { | 
 | 270 |       expect( 2 ); | 
 | 271 |       QUnit.stop(); | 
 | 272 |  | 
 | 273 |       var transport = new Thrift.Transport(); | 
 | 274 |       var protocol  = new Thrift.Protocol(transport); | 
 | 275 |       var client    = new ThriftTest.ThriftTestClient(protocol); | 
 | 276 |  | 
 | 277 |       var jqxhr = jQuery.ajax({ | 
 | 278 |         url: "/service", | 
 | 279 |         data: client.send_testI32(Math.pow(-2,31)), | 
 | 280 |         type: "POST", | 
 | 281 |         cache: false, | 
 | 282 |         dataType: "text", | 
 | 283 |         success: function(res){ | 
 | 284 |           transport.setRecvBuffer( res ); | 
 | 285 |           equals(client.recv_testI32(), Math.pow(-2,31)); | 
 | 286 |         }, | 
 | 287 |         error: function() { ok(false); }, | 
 | 288 |         complete: function() { | 
 | 289 |           ok(true); | 
 | 290 |           QUnit.start(); | 
 | 291 |         } | 
 | 292 |       }); | 
 | 293 |     }); | 
 | 294 |  | 
 | 295 |  | 
 | 296 |     test("testI64", function() { | 
 | 297 |       expect( 2 ); | 
 | 298 |       QUnit.stop(); | 
 | 299 |  | 
 | 300 |       var transport = new Thrift.Transport(); | 
 | 301 |       var protocol  = new Thrift.Protocol(transport); | 
 | 302 |       var client    = new ThriftTest.ThriftTestClient(protocol); | 
 | 303 |  | 
 | 304 |       jQuery.ajax({ | 
 | 305 |         url: "/service", | 
 | 306 |         data: client.send_testI64(Math.pow(-2,61)), | 
 | 307 |         type: "POST", | 
 | 308 |         cache: false, | 
 | 309 |         dataType: "text", | 
 | 310 |         success: function(res){ | 
 | 311 |           transport.setRecvBuffer( res ); | 
 | 312 |           equals(client.recv_testI64(), Math.pow(-2,61)); | 
 | 313 |         }, | 
 | 314 |         error: function() { ok(false); }, | 
 | 315 |         complete: function() { | 
 | 316 |           ok(true); | 
 | 317 |           QUnit.start(); | 
 | 318 |         } | 
 | 319 |       }); | 
 | 320 |     }); | 
 | 321 |  | 
 | 322 |  | 
 | 323 |  | 
 | 324 |     module("Async"); | 
 | 325 |  | 
 | 326 |     test("Double", function() { | 
 | 327 |       expect( 1 ); | 
 | 328 |  | 
 | 329 |       QUnit.stop(); | 
 | 330 |       client.testDouble(3.14159265, function(result) { | 
 | 331 |         equals(result, 3.14159265); | 
 | 332 |         QUnit.start(); | 
 | 333 |       }); | 
 | 334 |     }); | 
 | 335 |  | 
 | 336 |     test("Byte", function() { | 
 | 337 |       expect( 1 ); | 
 | 338 |  | 
 | 339 |       QUnit.stop(); | 
 | 340 |       client.testByte(0x01, function(result) { | 
 | 341 |         equals(result, 0x01); | 
 | 342 |         QUnit.start(); | 
 | 343 |       }); | 
 | 344 |     }); | 
 | 345 |  | 
 | 346 |     test("I32", function() { | 
 | 347 |       expect( 3 ); | 
 | 348 |  | 
 | 349 |       QUnit.stop(); | 
 | 350 |       client.testI32(Math.pow(2,30), function(result) { | 
 | 351 |         equals(result, Math.pow(2,30)); | 
 | 352 |         QUnit.start(); | 
 | 353 |       }); | 
 | 354 |  | 
 | 355 |       QUnit.stop(); | 
 | 356 |       var jqxhr = client.testI32(Math.pow(-2,31), function(result) { | 
 | 357 |         equals(result, Math.pow(-2,31)); | 
 | 358 |       }); | 
 | 359 |  | 
 | 360 |       jqxhr.success(function(result) { | 
 | 361 |         equals(result, Math.pow(-2,31)); | 
 | 362 |         QUnit.start(); | 
 | 363 |       }); | 
 | 364 |     }); | 
 | 365 |  | 
 | 366 |     test("I64", function() { | 
 | 367 |       expect( 4 ); | 
 | 368 |  | 
 | 369 |       QUnit.stop(); | 
 | 370 |       client.testI64(Math.pow(2,60), function(result) { | 
 | 371 |         equals(result, Math.pow(2,60)); | 
 | 372 |         QUnit.start(); | 
 | 373 |       }); | 
 | 374 |  | 
 | 375 |       QUnit.stop(); | 
 | 376 |       client.testI64(Math.pow(-2,61), function(result) { | 
 | 377 |         equals(result, Math.pow(-2,61)); | 
 | 378 |       }) | 
 | 379 |       .error( function(e) {  ok(false); } ) | 
 | 380 |       .success(function(result) { | 
 | 381 |         equals(result, Math.pow(-2,61)); | 
 | 382 |       }) | 
 | 383 |       .complete(function() { | 
 | 384 |         ok(true); | 
 | 385 |         QUnit.start(); | 
 | 386 |       }); | 
 | 387 |     }); | 
 | 388 |  | 
 | 389 |     test("Xception", function() { | 
 | 390 |       expect( 2 ); | 
 | 391 |  | 
 | 392 |       QUnit.stop(); | 
 | 393 |  | 
 | 394 |       var dfd = client.testException("Xception", function(result) { | 
 | 395 |         ok(false); | 
 | 396 |         QUnit.start(); | 
 | 397 |       }) | 
 | 398 |       .error(function(e){ | 
 | 399 |         equals(e.errorCode, 1001); | 
 | 400 |         equals(e.message, "Xception"); | 
 | 401 |         QUnit.start(); | 
 | 402 |       }); | 
 | 403 |     }); | 
 | 404 |  | 
 | 405 |  | 
| T Jake Luciani | efabb89 | 2010-07-28 22:31:12 +0000 | [diff] [blame] | 406 |   }); | 
 | 407 |   //]]> | 
 | 408 |   </script> | 
| T Jake Luciani | 322caa2 | 2010-02-15 03:24:55 +0000 | [diff] [blame] | 409 |  | 
 | 410 | </head> | 
| T Jake Luciani | efabb89 | 2010-07-28 22:31:12 +0000 | [diff] [blame] | 411 | <body> | 
| Roger Meier | 5aaa021 | 2010-11-04 12:20:05 +0000 | [diff] [blame] | 412 |   <h1 id="qunit-header">Thrift Javascript Bindings: Unit Test (<a href="https://svn.apache.org/repos/asf/thrift/trunk/test/ThriftTest.thrift">ThriftTest.thrift</a>)</h1> | 
| T Jake Luciani | efabb89 | 2010-07-28 22:31:12 +0000 | [diff] [blame] | 413 |   <h2 id="qunit-banner"></h2> | 
| Bryan Duxbury | 3ff373e | 2010-08-15 23:19:06 +0000 | [diff] [blame] | 414 |   <div id="qunit-testrunner-toolbar"></div>  | 
| T Jake Luciani | efabb89 | 2010-07-28 22:31:12 +0000 | [diff] [blame] | 415 |   <h2 id="qunit-userAgent"></h2> | 
 | 416 |   <ol id="qunit-tests"><li><!-- get valid xhtml strict--></li></ol> | 
 | 417 |   <p> | 
 | 418 |       <a href="http://validator.w3.org/check/referer"><img | 
 | 419 |           src="http://www.w3.org/Icons/valid-xhtml10" | 
 | 420 |           alt="Valid XHTML 1.0!" height="31" width="88" /></a> | 
 | 421 |   </p> | 
| T Jake Luciani | 322caa2 | 2010-02-15 03:24:55 +0000 | [diff] [blame] | 422 | </body> | 
 | 423 | </html> |