THRIFT-2443: node fails cross lang tests
authorra <ra@apache.org>
Wed, 2 Apr 2014 19:31:05 +0000 (12:31 -0700)
committerra <ra@apache.org>
Wed, 2 Apr 2014 19:31:05 +0000 (12:31 -0700)
Client: node
Patch: Randy Abernethy

adds support for recursive tests of i64 types and fixes cross
lang test failure with C++.

lib/nodejs/test/thrift_test_driver.js

index c61e99d..ccc105b 100644 (file)
@@ -17,7 +17,7 @@
  * under the License.\r
  */\r
 \r
- // This is the Node test driver for the standard Apache Thrift \r
+ // This is the Node.js test driver for the standard Apache Thrift \r
  // test service. The driver invokes every function defined in the \r
  // Thrift Test service with a representative range of parameters.\r
  //\r
 \r
 var assert = require('assert');\r
 var ttypes = require('./gen-nodejs/ThriftTest_types');\r
+var Int64 = require('node-int64');\r
 \r
 var ThriftTestDriver = exports.ThriftTestDriver = function(client, callback) {\r
        \r
-// deepEqual doesn't work with fields using node-int64\r
 function checkRecursively(map1, map2) {\r
   if (typeof map1 !== 'function' && typeof map2 !== 'function') {\r
     if (!map1 || typeof map1 !== 'object') {\r
+      //Handle int64 types (which use node-int64 in Node.js JavaScript)\r
+      if ((typeof map1 === "number") && (typeof map2 === "object") && \r
+          (map2.buffer) && (map2.buffer instanceof Buffer) && (map2.buffer.length === 8)) {\r
+        var n = new Int64(map2.buffer);\r
+        assert.equal(map1, n.toNumber());          \r
+      } else {\r
         assert.equal(map1, map2);\r
+      }\r
     } else {\r
       for (var key in map1) {\r
         checkRecursively(map1[key], map2[key]);\r
@@ -235,7 +242,7 @@ var crazy = new ttypes.Insanity({
 });\r
 var insanity = {\r
   "1":{ "2": crazy, "3": crazy },\r
-  "2":{ "6":{ "userMap":null, "xtructs":null } }\r
+  "2":{ "6":{ "userMap":{}, "xtructs":[] } }\r
 };\r
 client.testInsanity(crazy, function(err, response) {\r
   assert( ! err);\r