--- /dev/null
+/*\r
+ * Licensed to the Apache Software Foundation (ASF) under one\r
+ * or more contributor license agreements. See the NOTICE file\r
+ * distributed with this work for additional information\r
+ * regarding copyright ownership. The ASF licenses this file\r
+ * to you under the Apache License, Version 2.0 (the\r
+ * 'License'); you may not use this file except in compliance\r
+ * with the License. You may obtain a copy of the License at\r
+ *\r
+ * http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing,\r
+ * software distributed under the License is distributed on an\r
+ * 'AS IS' BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY\r
+ * KIND, either express or implied. See the License for the\r
+ * specific language governing permissions and limitations\r
+ * under the License.\r
+ */\r
+\r
+//This is the server side Node test handler for the standard \r
+// Apache Thrift test service.\r
+\r
+var ttypes = require('./gen-nodejs/ThriftTest_types');\r
+var TException = require('thrift/thrift').TException;\r
+\r
+var ThriftTestHandler = exports.ThriftTestHandler = {\r
+ testVoid: function(result) {\r
+ console.log('testVoid()');\r
+ result(null);\r
+ },\r
+ testString: function(thing, result) {\r
+ console.log('testString(\'' + thing + '\')');\r
+ result(null, thing);\r
+ },\r
+ testByte: function(thing, result) {\r
+ console.log('testByte(' + thing + ')');\r
+ result(null, thing);\r
+ },\r
+ testI32: function(thing, result) {\r
+ console.log('testI32(' + thing + ')');\r
+ result(null, thing);\r
+ },\r
+ testI64: function(thing, result) {\r
+ console.log('testI64(' + thing + ')');\r
+ result(null, thing);\r
+ },\r
+ testDouble: function(thing, result) {\r
+ console.log('testDouble(' + thing + ')');\r
+ result(null, thing);\r
+ },\r
+ testStruct: function(thing, result) {\r
+ console.log('testStruct(');\r
+ console.log(thing);\r
+ console.log(')');\r
+ result(null, thing);\r
+ },\r
+ testNest: function(nest, result) {\r
+ console.log('testNest(');\r
+ console.log(nest);\r
+ console.log(')');\r
+ result(null, nest);\r
+ },\r
+ testMap: function(thing, result) {\r
+ console.log('testMap(');\r
+ console.log(thing);\r
+ console.log(')');\r
+ result(null, thing);\r
+ },\r
+ testStringMap: function(thing, result) {\r
+ console.log('testStringMap(');\r
+ console.log(thing);\r
+ console.log(')');\r
+ result(null, thing);\r
+ },\r
+ testSet: function(thing, result) {\r
+ console.log('testSet(');\r
+ console.log(thing);\r
+ console.log(')');\r
+ result(null, thing);\r
+ },\r
+ testList: function(thing, result) {\r
+ console.log('testList(');\r
+ console.log(thing);\r
+ console.log(')');\r
+ result(null, thing);\r
+ },\r
+ testEnum: function(thing, result) {\r
+ console.log('testEnum(' + thing + ')');\r
+ result(null, thing);\r
+ },\r
+ testTypedef: function(thing, result) {\r
+ console.log('testTypedef(' + thing + ')');\r
+ result(null, thing);\r
+ },\r
+ testMapMap: function(hello, result) {\r
+ console.log('testMapMap(' + hello + ')');\r
+\r
+ var mapmap = [];\r
+ var pos = [];\r
+ var neg = [];\r
+ for (var i = 1; i < 5; i++) {\r
+ pos[i] = i;\r
+ neg[-i] = -i;\r
+ }\r
+ mapmap[4] = pos;\r
+ mapmap[-4] = neg;\r
+\r
+ result(null, mapmap);\r
+ },\r
+ testInsanity: function(argument, result) {\r
+ console.log('testInsanity(');\r
+ console.log(argument);\r
+ console.log(')');\r
+\r
+ var hello = new ttypes.Xtruct();\r
+ hello.string_thing = 'Hello2';\r
+ hello.byte_thing = 2;\r
+ hello.i32_thing = 2;\r
+ hello.i64_thing = 2;\r
+\r
+ var goodbye = new ttypes.Xtruct();\r
+ goodbye.string_thing = 'Goodbye4';\r
+ goodbye.byte_thing = 4;\r
+ goodbye.i32_thing = 4;\r
+ goodbye.i64_thing = 4;\r
+\r
+ var crazy = new ttypes.Insanity();\r
+ crazy.userMap = [];\r
+ crazy.userMap[ttypes.Numberz.EIGHT] = 8;\r
+ crazy.userMap[ttypes.Numberz.FIVE] = 5;\r
+ crazy.xtructs = [goodbye, hello];\r
+\r
+ var first_map = [];\r
+ var second_map = [];\r
+\r
+ first_map[ttypes.Numberz.TWO] = crazy;\r
+ first_map[ttypes.Numberz.THREE] = crazy;\r
+\r
+ var looney = new ttypes.Insanity();\r
+ second_map[ttypes.Numberz.SIX] = looney;\r
+\r
+ var insane = [];\r
+ insane[1] = first_map;\r
+ insane[2] = second_map;\r
+\r
+ console.log('insane result:');\r
+ console.log(insane);\r
+ result(null, insane);\r
+ },\r
+ testMulti: function(arg0, arg1, arg2, arg3, arg4, arg5, result) {\r
+ console.log('testMulti()');\r
+\r
+ var hello = new ttypes.Xtruct();\r
+ hello.string_thing = 'Hello2';\r
+ hello.byte_thing = arg0;\r
+ hello.i32_thing = arg1;\r
+ hello.i64_thing = arg2;\r
+ result(null, hello);\r
+ },\r
+ testException: function(arg, result) {\r
+ console.log('testException('+arg+')');\r
+ if (arg === 'Xception') {\r
+ var x = new ttypes.Xception();\r
+ x.errorCode = 1001;\r
+ x.message = arg;\r
+ result(x);\r
+ } else if (arg === 'TException') {\r
+ result(new TException(arg));\r
+ } else {\r
+ result(null);\r
+ }\r
+ },\r
+ testMultiException: function(arg0, arg1, result) {\r
+ console.log('testMultiException(' + arg0 + ', ' + arg1 + ')');\r
+ if (arg0 === ('Xception')) {\r
+ var x = new ttypes.Xception();\r
+ x.errorCode = 1001;\r
+ x.message = 'This is an Xception';\r
+ result(x);\r
+ } else if (arg0 === ('Xception2')) {\r
+ var x2 = new ttypes.Xception2();\r
+ x2.errorCode = 2002;\r
+ x2.struct_thing = new ttypes.Xtruct();\r
+ x2.struct_thing.string_thing = 'This is an Xception2';\r
+ result(x2);\r
+ }\r
+\r
+ var res = new ttypes.Xtruct();\r
+ res.string_thing = arg1;\r
+ result(null, res);\r
+ },\r
+ testOneway: function(sleepFor, result) {\r
+ console.log('testOneway(' + sleepFor + ') => JavaScript (like Rust) never sleeps!');\r
+ }\r
+}; //ThriftTestSvcHandler\r
+++ /dev/null
-\feff/*\r
- * Licensed to the Apache Software Foundation (ASF) under one\r
- * or more contributor license agreements. See the NOTICE file\r
- * distributed with this work for additional information\r
- * regarding copyright ownership. The ASF licenses this file\r
- * to you under the Apache License, Version 2.0 (the\r
- * "License"); you may not use this file except in compliance\r
- * with the License. You may obtain a copy of the License at\r
- *\r
- * http://www.apache.org/licenses/LICENSE-2.0\r
- *\r
- * Unless required by applicable law or agreed to in writing,\r
- * software distributed under the License is distributed on an\r
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY\r
- * KIND, either express or implied. See the License for the\r
- * specific language governing permissions and limitations\r
- * under the License.\r
- */\r
- /* jshint -W100 */\r
- \r
-/*\r
- * JavaScript test suite\r
- */\r
-\r
-var transport = new Thrift.Transport("/service");\r
-var protocol = new Thrift.Protocol(transport);\r
-var client = new ThriftTest.ThriftTestClient(protocol);\r
-\r
-// all Languages in UTF-8\r
-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, \202aNorsk (nynorsk)\202c, \202aNorsk (bokmål)\202c, 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ú, 粵語";\r
- \r
-function checkRecursively(map1, map2) {\r
- if (typeof map1 !== 'function' && typeof map2 !== 'function') {\r
- if (!map1 || typeof map1 !== 'object') {\r
- equal(map1, map2);\r
- } else {\r
- for (var key in map1) {\r
- checkRecursively(map1[key], map2[key]);\r
- }\r
- }\r
- }\r
-}\r
-\r
-module("Base Types");\r
-\r
- test("Void", function() {\r
- equal(client.testVoid(), undefined);\r
- });\r
- test("String", function() {\r
- equal(client.testString(''), '');\r
- equal(client.testString(stringTest), stringTest);\r
-\r
- var specialCharacters = 'quote: \" backslash:' +\r
- ' forwardslash-escaped: \/ ' +\r
- ' backspace: \b formfeed: \f newline: \n return: \r tab: ' +\r
- ' now-all-of-them-together: "\\\/\b\n\r\t' +\r
- ' now-a-bunch-of-junk: !@#$%&()(&%$#{}{}<><><';\r
- equal(client.testString(specialCharacters),specialCharacters);\r
- });\r
- test("Double", function() {\r
- equal(client.testDouble(0), 0);\r
- equal(client.testDouble(-1), -1);\r
- equal(client.testDouble(3.14), 3.14);\r
- equal(client.testDouble(Math.pow(2,60)), Math.pow(2,60));\r
- });\r
- test("Byte", function() {\r
- equal(client.testByte(0), 0);\r
- equal(client.testByte(0x01), 0x01);\r
- });\r
- test("I32", function() {\r
- equal(client.testI32(0), 0);\r
- equal(client.testI32(Math.pow(2,30)), Math.pow(2,30));\r
- equal(client.testI32(-Math.pow(2,30)), -Math.pow(2,30));\r
- });\r
- test("I64", function() {\r
- equal(client.testI64(0), 0);\r
- //This is usually 2^60 but JS cannot represent anything over 2^52 accurately\r
- equal(client.testI64(Math.pow(2,52)), Math.pow(2,52));\r
- equal(client.testI64(-Math.pow(2,52)), -Math.pow(2,52));\r
- });\r
-\r
-\r
-module("Structured Types");\r
-\r
- test("Struct", function() {\r
- var structTestInput = new ThriftTest.Xtruct();\r
- structTestInput.string_thing = 'worked';\r
- structTestInput.byte_thing = 0x01;\r
- structTestInput.i32_thing = Math.pow(2,30);\r
- //This is usually 2^60 but JS cannot represent anything over 2^52 accurately\r
- structTestInput.i64_thing = Math.pow(2,52);\r
-\r
- var structTestOutput = client.testStruct(structTestInput);\r
-\r
- equal(structTestOutput.string_thing, structTestInput.string_thing);\r
- equal(structTestOutput.byte_thing, structTestInput.byte_thing);\r
- equal(structTestOutput.i32_thing, structTestInput.i32_thing);\r
- equal(structTestOutput.i64_thing, structTestInput.i64_thing);\r
- \r
- equal(JSON.stringify(structTestOutput), JSON.stringify(structTestInput));\r
- });\r
-\r
- test("Nest", function() {\r
- var xtrTestInput = new ThriftTest.Xtruct();\r
- xtrTestInput.string_thing = 'worked';\r
- xtrTestInput.byte_thing = 0x01;\r
- xtrTestInput.i32_thing = Math.pow(2,30);\r
- //This is usually 2^60 but JS cannot represent anything over 2^52 accurately\r
- xtrTestInput.i64_thing = Math.pow(2,52);\r
- \r
- var nestTestInput = new ThriftTest.Xtruct2();\r
- nestTestInput.byte_thing = 0x02;\r
- nestTestInput.struct_thing = xtrTestInput;\r
- nestTestInput.i32_thing = Math.pow(2,15);\r
- \r
- var nestTestOutput = client.testNest(nestTestInput);\r
- \r
- equal(nestTestOutput.byte_thing, nestTestInput.byte_thing);\r
- equal(nestTestOutput.struct_thing.string_thing, nestTestInput.struct_thing.string_thing);\r
- equal(nestTestOutput.struct_thing.byte_thing, nestTestInput.struct_thing.byte_thing);\r
- equal(nestTestOutput.struct_thing.i32_thing, nestTestInput.struct_thing.i32_thing);\r
- equal(nestTestOutput.struct_thing.i64_thing, nestTestInput.struct_thing.i64_thing);\r
- equal(nestTestOutput.i32_thing, nestTestInput.i32_thing);\r
- \r
- equal(JSON.stringify(nestTestOutput), JSON.stringify(nestTestInput));\r
- });\r
-\r
- test("Map", function() {\r
- var mapTestInput = {7:77, 8:88, 9:99};\r
-\r
- var mapTestOutput = client.testMap(mapTestInput);\r
-\r
- for (var key in mapTestOutput) {\r
- equal(mapTestOutput[key], mapTestInput[key]);\r
- }\r
- });\r
-\r
- test("StringMap", function() {\r
- var mapTestInput = {\r
- "a":"123", "a b":"with spaces ", "same":"same", "0":"numeric key",\r
- "longValue":stringTest, stringTest:"long key"\r
- };\r
-\r
- var mapTestOutput = client.testStringMap(mapTestInput);\r
-\r
- for (var key in mapTestOutput) {\r
- equal(mapTestOutput[key], mapTestInput[key]);\r
- }\r
- });\r
-\r
- test("Set", function() {\r
- var setTestInput = [1,2,3];\r
- ok(client.testSet(setTestInput), setTestInput);\r
- });\r
-\r
- test("List", function() {\r
- var listTestInput = [1,2,3];\r
- ok(client.testList(listTestInput), listTestInput);\r
- });\r
-\r
- test("Enum", function() {\r
- equal(client.testEnum(ThriftTest.Numberz.ONE), ThriftTest.Numberz.ONE);\r
- });\r
-\r
- test("TypeDef", function() {\r
- equal(client.testTypedef(69), 69);\r
- });\r
-\r
-\r
-module("deeper!");\r
-\r
- test("MapMap", function() {\r
- var mapMapTestExpectedResult = {\r
- "4":{"1":1,"2":2,"3":3,"4":4},\r
- "-4":{"-4":-4, "-3":-3, "-2":-2, "-1":-1}\r
- };\r
-\r
- var mapMapTestOutput = client.testMapMap(1);\r
-\r
-\r
- for (var key in mapMapTestOutput) {\r
- for (var key2 in mapMapTestOutput[key]) {\r
- equal(mapMapTestOutput[key][key2], mapMapTestExpectedResult[key][key2]);\r
- }\r
- }\r
- \r
- checkRecursively(mapMapTestOutput, mapMapTestExpectedResult);\r
- });\r
-\r
-\r
-module("Exception");\r
-\r
- test("Xception", function() {\r
- expect(2);\r
- try{\r
- client.testException("Xception");\r
- }catch(e){\r
- equal(e.errorCode, 1001);\r
- equal(e.message, "Xception");\r
- }\r
- });\r
-\r
- test("no Exception", 0, function() {\r
- try{\r
- client.testException("no Exception");\r
- }catch(e){\r
- ok(false);\r
- }\r
- });\r
-\r
- test("TException", function() {\r
- //ThriftTest does not list TException as a legal exception so it will\r
- // generate an exception on the server that does not propagate back to \r
- // the client. This test has been modified to equate to "no exception"\r
- expect(1);\r
- try{\r
- client.testException("TException");\r
- } catch(e) {\r
- //ok(false);\r
- }\r
- ok(true);\r
- });\r
-\r
-\r
-module("Insanity");\r
-\r
- test("testInsanity", function() {\r
- var insanity = {\r
- "1":{\r
- "2":{\r
- "userMap":{ "5":5, "8":8 },\r
- "xtructs":[{\r
- "string_thing":"Goodbye4",\r
- "byte_thing":4,\r
- "i32_thing":4,\r
- "i64_thing":4\r
- },\r
- {\r
- "string_thing":"Hello2",\r
- "byte_thing":2,\r
- "i32_thing":2,\r
- "i64_thing":2\r
- }\r
- ]\r
- },\r
- "3":{\r
- "userMap":{ "5":5, "8":8 },\r
- "xtructs":[{\r
- "string_thing":"Goodbye4",\r
- "byte_thing":4,\r
- "i32_thing":4,\r
- "i64_thing":4\r
- },\r
- {\r
- "string_thing":"Hello2",\r
- "byte_thing":2,\r
- "i32_thing":2,\r
- "i64_thing":2\r
- }\r
- ]\r
- }\r
- },\r
- "2":{ "6":{ "userMap":null, "xtructs":null } }\r
- };\r
- var res = client.testInsanity(new ThriftTest.Insanity());\r
- ok(res, JSON.stringify(res));\r
- ok(insanity, JSON.stringify(insanity));\r
-\r
- checkRecursively(res, insanity);\r
- });\r
-\r
-\r
-//////////////////////////////////\r
-//Run same tests asynchronously\r
-jQuery.ajaxSetup({ timeout: 0 });\r
-$(document).ajaxError( function() { QUnit.start(); } );\r
-\r
-module("Async Manual");\r
-\r
- test("testI32", function() {\r
- expect( 2 );\r
- QUnit.stop();\r
-\r
- var transport = new Thrift.Transport();\r
- var protocol = new Thrift.Protocol(transport);\r
- var client = new ThriftTest.ThriftTestClient(protocol);\r
-\r
- var jqxhr = jQuery.ajax({\r
- url: "/service",\r
- data: client.send_testI32(Math.pow(-2,31)),\r
- type: "POST",\r
- cache: false,\r
- dataType: "text",\r
- success: function(res){\r
- transport.setRecvBuffer( res );\r
- equal(client.recv_testI32(), Math.pow(-2,31));\r
- },\r
- error: function() { ok(false); },\r
- complete: function() {\r
- ok(true);\r
- QUnit.start();\r
- }\r
- });\r
- });\r
-\r
-\r
- test("testI64", function() {\r
- expect( 2 );\r
- QUnit.stop();\r
-\r
- var transport = new Thrift.Transport();\r
- var protocol = new Thrift.Protocol(transport);\r
- var client = new ThriftTest.ThriftTestClient(protocol);\r
-\r
- jQuery.ajax({\r
- url: "/service",\r
- //This is usually 2^61 but JS cannot represent anything over 2^52 accurately\r
- data: client.send_testI64(Math.pow(-2,52)),\r
- type: "POST",\r
- cache: false,\r
- dataType: "text",\r
- success: function(res){\r
- transport.setRecvBuffer( res );\r
- //This is usually 2^61 but JS cannot represent anything over 2^52 accurately\r
- equal(client.recv_testI64(), Math.pow(-2,52));\r
- },\r
- error: function() { ok(false); },\r
- complete: function() {\r
- ok(true);\r
- QUnit.start();\r
- }\r
- });\r
- });\r
-\r
-\r
-module("Async");\r
-\r
- test("Double", function() {\r
- expect( 1 );\r
-\r
- QUnit.stop();\r
- client.testDouble(3.14159265, function(result) {\r
- equal(result, 3.14159265);\r
- QUnit.start();\r
- });\r
- });\r
-\r
- test("Byte", function() {\r
- expect( 1 );\r
-\r
- QUnit.stop();\r
- client.testByte(0x01, function(result) {\r
- equal(result, 0x01);\r
- QUnit.start();\r
- });\r
- });\r
-\r
- test("I32", function() {\r
- expect( 3 );\r
-\r
- QUnit.stop();\r
- client.testI32(Math.pow(2,30), function(result) {\r
- equal(result, Math.pow(2,30));\r
- QUnit.start();\r
- });\r
-\r
- QUnit.stop();\r
- var jqxhr = client.testI32(Math.pow(-2,31), function(result) {\r
- equal(result, Math.pow(-2,31));\r
- });\r
-\r
- jqxhr.success(function(result) {\r
- equal(result, Math.pow(-2,31));\r
- QUnit.start();\r
- });\r
- });\r
-\r
- test("I64", function() {\r
- expect( 4 );\r
-\r
- QUnit.stop();\r
- //This is usually 2^60 but JS cannot represent anything over 2^52 accurately\r
- client.testI64(Math.pow(2,52), function(result) {\r
- equal(result, Math.pow(2,52));\r
- QUnit.start();\r
- });\r
-\r
- QUnit.stop();\r
- //This is usually 2^60 but JS cannot represent anything over 2^52 accurately\r
- client.testI64(Math.pow(-2,52), function(result) {\r
- equal(result, Math.pow(-2,52));\r
- })\r
- .error( function(xhr, status, e) { ok(false, e.message); } )\r
- .success(function(result) {\r
- //This is usually 2^60 but JS cannot represent anything over 2^52 accurately\r
- equal(result, Math.pow(-2,52));\r
- })\r
- .complete(function() {\r
- ok(true);\r
- QUnit.start();\r
- });\r
- });\r
-\r
- test("Xception", function() {\r
- expect( 2 );\r
-\r
- QUnit.stop();\r
-\r
- var dfd = client.testException("Xception", function(result) {\r
- ok(false);\r
- QUnit.start();\r
- })\r
- .error(function(xhr, status, e){\r
- equal(e.errorCode, 1001);\r
- equal(e.message, "Xception");\r
- //QUnit.start();\r
- //Note start is not required here because:\r
- //$(document).ajaxError( function() { QUnit.start(); } );\r
- });\r
- });\r