T Jake Luciani | efabb89 | 2010-07-28 22:31:12 +0000 | [diff] [blame] | 1 | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> |
| 2 | <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] | 3 | <head> |
T Jake Luciani | efabb89 | 2010-07-28 22:31:12 +0000 | [diff] [blame] | 4 | <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> |
| 5 | <title>Thrift Javascript Bindings: Unit Test</title> |
T Jake Luciani | 322caa2 | 2010-02-15 03:24:55 +0000 | [diff] [blame] | 6 | |
T Jake Luciani | efabb89 | 2010-07-28 22:31:12 +0000 | [diff] [blame] | 7 | <script src="/thrift.js" type="text/javascript" charset="utf-8"></script> |
| 8 | <script src="gen-js/ThriftTest_types.js" type="text/javascript" charset="utf-8"></script> |
| 9 | <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] | 10 | |
T Jake Luciani | efabb89 | 2010-07-28 22:31:12 +0000 | [diff] [blame] | 11 | <!-- jQuery --> |
| 12 | <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js" charset="utf-8"></script> |
| 13 | |
| 14 | <!-- QUnit Test framework--> |
| 15 | <script type="text/javascript" src="http://github.com/jquery/qunit/raw/master/qunit/qunit.js" charset="utf-8"></script> |
| 16 | <link rel="stylesheet" href="http://github.com/jquery/qunit/raw/master/qunit/qunit.css" type="text/css" media="screen" /> |
| 17 | |
| 18 | <script type="text/javascript" charset="utf-8"> |
| 19 | //<![CDATA[ |
| 20 | $(document).ready(function(){ |
| 21 | var transport = new Thrift.Transport("/service") |
| 22 | var protocol = new Thrift.Protocol(transport) |
| 23 | var client = new ThriftTest.ThriftTestClient(protocol) |
| 24 | |
| 25 | |
| 26 | module("Base Types"); |
| 27 | |
| 28 | test("String", function() { |
| 29 | equals(client.testString("works"), "works"); |
| 30 | }); |
| 31 | test("String UTF-8", function() { |
| 32 | var languagesUtf8 = "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ú, 粵語"; |
| 33 | equals(client.testString(languagesUtf8), languagesUtf8); |
| 34 | }); |
| 35 | test("Double", function() { |
| 36 | equals(client.testDouble(3.14), 3.14); |
| 37 | }); |
| 38 | test("Byte", function() { |
| 39 | equals(client.testByte(0x01), 0x01); |
| 40 | }); |
| 41 | test("I32", function() { |
| 42 | equals(client.testI32(Math.pow(2,30)), Math.pow(2,30)); |
| 43 | }); |
| 44 | test("I64", function() { |
| 45 | equals(client.testI64(Math.pow(2,60)), Math.pow(2,60)); |
| 46 | }); |
| 47 | |
| 48 | |
| 49 | module("Structured Types"); |
| 50 | |
| 51 | var insanity = new ThriftTest.Insanity() |
| 52 | insanity.userMap[ThriftTest.Numberz.ONE] = 1 |
| 53 | insanity.userMap[ThriftTest.Numberz.TWO] = 2 |
| 54 | |
| 55 | var xtr = new ThriftTest.Xtruct() |
| 56 | xtr.string_thing = 'worked' |
| 57 | insanity.xtructs.push(xtr) |
| 58 | |
| 59 | var xtr2= new ThriftTest.Xtruct2() |
| 60 | xtr2.struct_thing = xtr |
| 61 | |
| 62 | var list = [1,2,3] |
| 63 | |
| 64 | test("Struct", function() { |
| 65 | equals(client.testStruct(xtr).string_thing, "worked"); |
| 66 | }); |
| 67 | test("Nest", function() { |
| 68 | equals(client.testNest(xtr2).struct_thing.string_thing, "worked"); |
| 69 | }); |
| 70 | test("Map", function() { |
| 71 | equals(client.testMap(insanity.userMap)[ThriftTest.Numberz.ONE], 1); |
| 72 | }); |
| 73 | test("List", function() { |
| 74 | same(client.testList(list), list); |
| 75 | }); |
| 76 | test("Set", function() { |
| 77 | same(client.testSet(list), list); |
| 78 | }); |
| 79 | test("Enum", function() { |
| 80 | equals(client.testEnum(ThriftTest.Numberz.ONE), ThriftTest.Numberz.ONE); |
| 81 | }); |
| 82 | |
| 83 | |
| 84 | module("Exception"); |
| 85 | |
| 86 | test("Xception", function() { |
| 87 | expect(2); |
| 88 | try{ |
| 89 | client.testException("Xception"); |
| 90 | }catch(e){ |
| 91 | equals(e.errorCode, 1); |
| 92 | equals(e.message, "Xception"); |
| 93 | } |
| 94 | }); |
| 95 | |
| 96 | test("ApplicationException", function() { |
| 97 | expect(1); |
| 98 | try{ |
| 99 | client.testException("ApplicationException"); |
| 100 | }catch(e){ |
| 101 | equals(e.message, "ApplicationException"); |
| 102 | } |
| 103 | }); |
| 104 | |
| 105 | test("no Exception", function() { |
| 106 | expect(1); |
| 107 | try{ |
| 108 | client.testException("no Exception"); |
| 109 | }catch(e){ |
| 110 | equals(e.message, "no Exception"); |
| 111 | } |
| 112 | }); |
| 113 | |
| 114 | |
| 115 | module("Insanity"); |
| 116 | |
| 117 | test("testInsanity", function() { |
| 118 | var res = client.testInsanity(insanity); |
| 119 | equals(res["1"]["1"].xtructs[0].string_thing, "worked"); |
| 120 | }); |
| 121 | |
| 122 | }); |
| 123 | //]]> |
| 124 | </script> |
T Jake Luciani | 322caa2 | 2010-02-15 03:24:55 +0000 | [diff] [blame] | 125 | |
| 126 | </head> |
T Jake Luciani | efabb89 | 2010-07-28 22:31:12 +0000 | [diff] [blame] | 127 | <body> |
T Jake Luciani | 322caa2 | 2010-02-15 03:24:55 +0000 | [diff] [blame] | 128 | |
T Jake Luciani | efabb89 | 2010-07-28 22:31:12 +0000 | [diff] [blame] | 129 | <script type="text/javascript" charset="utf-8"> |
| 130 | //<![CDATA[ |
T Jake Luciani | 322caa2 | 2010-02-15 03:24:55 +0000 | [diff] [blame] | 131 | |
| 132 | ////////////////////////////////// |
| 133 | //Run same tests asynchronously |
T Jake Luciani | efabb89 | 2010-07-28 22:31:12 +0000 | [diff] [blame] | 134 | /* |
T Jake Luciani | 322caa2 | 2010-02-15 03:24:55 +0000 | [diff] [blame] | 135 | var transport = new Thrift.Transport() |
| 136 | var protocol = new Thrift.Protocol(transport) |
| 137 | var client = new ThriftTest.ThriftTestClient(protocol) |
| 138 | |
T Jake Luciani | efabb89 | 2010-07-28 22:31:12 +0000 | [diff] [blame] | 139 | document.write("<h2>Asynchronous Example<\/h2>") |
T Jake Luciani | 322caa2 | 2010-02-15 03:24:55 +0000 | [diff] [blame] | 140 | jQuery.ajax({ |
| 141 | url: "/service", |
| 142 | data: client.send_testI32(Math.pow(2,30)), |
| 143 | type: "POST", |
| 144 | cache: false, |
| 145 | success: function(res){ |
| 146 | var _transport = new Thrift.Transport() |
| 147 | var _protocol = new Thrift.Protocol(_transport) |
| 148 | var _client = new ThriftTest.ThriftTestClient(_protocol) |
| 149 | |
| 150 | _transport.setRecvBuffer( res ) |
| 151 | |
| 152 | var v = _client.recv_testI32() |
| 153 | $("#body").append("client.testI32() => "+(v == Math.pow(2,30))+"<br/>") |
| 154 | |
| 155 | } |
| 156 | }) |
| 157 | |
| 158 | jQuery.ajax({ |
| 159 | url: "/service", |
| 160 | data: client.send_testI64(Math.pow(2,60)), |
| 161 | type: "POST", |
| 162 | cache: false, |
| 163 | success: function(res){ |
| 164 | var _transport = new Thrift.Transport() |
| 165 | var _protocol = new Thrift.Protocol(_transport) |
| 166 | var _client = new ThriftTest.ThriftTestClient(_protocol) |
| 167 | |
| 168 | _transport.setRecvBuffer( res ) |
| 169 | |
| 170 | var v = _client.recv_testI64() |
| 171 | $("#body").append("client.testI64() => "+(v == Math.pow(2,60))+"<br/>") |
| 172 | |
| 173 | } |
| 174 | }) |
T Jake Luciani | efabb89 | 2010-07-28 22:31:12 +0000 | [diff] [blame] | 175 | */ |
T Jake Luciani | 322caa2 | 2010-02-15 03:24:55 +0000 | [diff] [blame] | 176 | |
T Jake Luciani | efabb89 | 2010-07-28 22:31:12 +0000 | [diff] [blame] | 177 | //]]> |
| 178 | </script> |
| 179 | <h1 id="qunit-header">Thrift Javascript Bindings: Unit Test (<a href="https://svn.apache.org/repos/asf/incubator/thrift/trunk/test/ThriftTest.thrift">ThriftTest.thrift</a>)</h1> |
| 180 | <h2 id="qunit-banner"></h2> |
| 181 | <h2 id="qunit-userAgent"></h2> |
| 182 | <ol id="qunit-tests"><li><!-- get valid xhtml strict--></li></ol> |
| 183 | <p> |
| 184 | <a href="http://validator.w3.org/check/referer"><img |
| 185 | src="http://www.w3.org/Icons/valid-xhtml10" |
| 186 | alt="Valid XHTML 1.0!" height="31" width="88" /></a> |
| 187 | </p> |
T Jake Luciani | 322caa2 | 2010-02-15 03:24:55 +0000 | [diff] [blame] | 188 | </body> |
| 189 | </html> |