THRIFT-2886 Integrate binary type in standard Thrift cross test
Client: C_glib, C++, D, Erlang, Go, Haskell, Lua, Java/Me, JavaScript, Node, Ocaml, Perl, PHP, Python, Ruby
Patch: Jens Geyer

This closes #341

Minimal server-side implementations and TODO stubs for various languages to let "make check" succeeed.
Not contained in this patch and still TODO:
- client side implementations, i.e. calls to testBinary() and appropriate tests
- server side hex printout missing for some languages
diff --git a/lib/c_glib/test/testthrifttestclient.cpp b/lib/c_glib/test/testthrifttestclient.cpp
index f4e3250..4241f1c 100755
--- a/lib/c_glib/test/testthrifttestclient.cpp
+++ b/lib/c_glib/test/testthrifttestclient.cpp
@@ -86,6 +86,11 @@
     return thing;
   }
 
+  void testBinary(string& out, const string &thing) {
+    printf("[C -> C++] testBinary(\"%s\")\n", thing.c_str());
+    out = thing;
+  }
+
   void testStruct(Xtruct& out, const Xtruct &thing) {
     printf("[C -> C++] testStruct({\"%s\", %d, %d, %lld})\n", thing.string_thing.c_str(), (int)thing.byte_thing, thing.i32_thing, thing.i64_thing);
     out = thing;
diff --git a/lib/d/test/thrift_test_client.d b/lib/d/test/thrift_test_client.d
index a258b64..fd53328 100644
--- a/lib/d/test/thrift_test_client.d
+++ b/lib/d/test/thrift_test_client.d
@@ -159,6 +159,8 @@
     if (trace) writefln(" = %s", dub);
     enforce(dub == -5.2098523);
 
+	// TODO: add testBinary() call
+	
     Xtruct out1;
     out1.string_thing = "Zero";
     out1.byte_thing = 1;
diff --git a/lib/d/test/thrift_test_server.d b/lib/d/test/thrift_test_server.d
index 993c063..1608a57 100644
--- a/lib/d/test/thrift_test_server.d
+++ b/lib/d/test/thrift_test_server.d
@@ -81,6 +81,11 @@
     return thing;
   }
 
+  override string testBinary(string thing) {
+    if (trace_) writefln("testBinary(\"%s\")", thing);
+    return thing;
+  }
+
   override Xtruct testStruct(ref const(Xtruct) thing) {
     if (trace_) writefln("testStruct({\"%s\", %s, %s, %s})",
       thing.string_thing, thing.byte_thing, thing.i32_thing, thing.i64_thing);
diff --git a/lib/erl/test/test_client.erl b/lib/erl/test/test_client.erl
index db4d2d1..4e85c47 100644
--- a/lib/erl/test/test_client.erl
+++ b/lib/erl/test/test_client.erl
@@ -83,6 +83,7 @@
   {Client06, {ok, 0}}               = thrift_client:call(Client05, testI32, [0]),
   {Client07, {ok, -34359738368}}    = thrift_client:call(Client06, testI64, [-34359738368]),
   {Client08, {ok, -5.2098523}}      = thrift_client:call(Client07, testDouble, [-5.2098523]),
+  %% TODO: add testBinary() call
   {Client09, {ok, DemoXtruct}}      = thrift_client:call(Client08, testStruct, [DemoXtruct]),
   {Client10, {ok, DemoNest}}        = thrift_client:call(Client09, testNest, [DemoNest]),
   {Client11, {ok, DemoDict}}        = thrift_client:call(Client10, testMap, [DemoDict]),
diff --git a/lib/erl/test/test_server.erl b/lib/erl/test/test_server.erl
index a4145d6..77357ff 100644
--- a/lib/erl/test/test_server.erl
+++ b/lib/erl/test/test_server.erl
@@ -81,6 +81,10 @@
     io:format("testDouble: ~p~n", [Double]),
     {reply, Double};
 
+handle_function(testBinary, {S}) when is_binary(S) ->
+    io:format("testBinary: ~p~n", [S]),
+    {reply, S};
+
 handle_function(testStruct,
                 {Struct = #'Xtruct'{string_thing = String,
                                  byte_thing = Byte,
diff --git a/lib/go/test/tests/thrifttest_driver.go b/lib/go/test/tests/thrifttest_driver.go
index b6188e4..915383f 100644
--- a/lib/go/test/tests/thrifttest_driver.go
+++ b/lib/go/test/tests/thrifttest_driver.go
@@ -127,6 +127,8 @@
 		t.Fatal("TestDouble(-7.012052175215044) failed")
 	}
 
+	// TODO: add testBinary() call
+
 	out := thrifttest.NewXtruct()
 	out.StringThing = "Zero"
 	out.ByteThing = 1
diff --git a/lib/go/test/tests/thrifttest_handler.go b/lib/go/test/tests/thrifttest_handler.go
index 1bbd7de..eef45d5 100644
--- a/lib/go/test/tests/thrifttest_handler.go
+++ b/lib/go/test/tests/thrifttest_handler.go
@@ -72,6 +72,10 @@
 	return thing, nil
 }
 
+func (p *ThriftTestHandler) TestBinary(thing []byte) (r []byte, err error) {
+	return thing, nil
+}
+
 func (p *ThriftTestHandler) TestStruct(thing *thrifttest.Xtruct) (r *thrifttest.Xtruct, err error) {
 	return thing, nil
 }
diff --git a/lib/java/test/org/apache/thrift/server/ServerTestBase.java b/lib/java/test/org/apache/thrift/server/ServerTestBase.java
index 4cbb511..a2836aa 100755
--- a/lib/java/test/org/apache/thrift/server/ServerTestBase.java
+++ b/lib/java/test/org/apache/thrift/server/ServerTestBase.java
@@ -26,6 +26,8 @@
 import java.util.Map;
 import java.util.Set;
 
+import java.nio.ByteBuffer;
+
 import junit.framework.TestCase;
 
 import org.apache.thrift.TException;
@@ -83,7 +85,13 @@
       System.out.print("testDouble(" + thing + ")\n");
       return thing;
     }
-  
+
+    public ByteBuffer testBinary(ByteBuffer thing) {
+      String hexstr = "TODO: toHexString(thing)";
+	  System.out.print("testBinary(" + hexstr + ")\n");
+      return thing;
+    }
+
     public Xtruct testStruct(Xtruct thing) {
       System.out.print("testStruct({" +
                        "\"" + thing.string_thing + "\", " +
@@ -596,6 +604,11 @@
             resultHandler.onComplete(handler.testDouble(thing));
         }
 
+        @Override 
+        public void testBinary(ByteBuffer thing, AsyncMethodCallback resultHandler) throws TException {
+            resultHandler.onComplete(handler.testBinary(thing));
+        }
+
         @Override
         public void testStruct(Xtruct thing, AsyncMethodCallback resultHandler) throws TException {
             resultHandler.onComplete(handler.testStruct(thing));
diff --git a/lib/java/test/org/apache/thrift/test/TestClient.java b/lib/java/test/org/apache/thrift/test/TestClient.java
index 4e7e507..b54461e 100644
--- a/lib/java/test/org/apache/thrift/test/TestClient.java
+++ b/lib/java/test/org/apache/thrift/test/TestClient.java
@@ -254,6 +254,11 @@
         }
 
         /**
+         * BINARY TEST
+         */
+        System.out.print("TODO: testBinary( ... )");
+
+        /**
          * STRUCT TEST
          */
         System.out.print("testStruct({\"Zero\", 1, -3, -5})");
diff --git a/lib/js/test/test-async.js b/lib/js/test/test-async.js
index 4935fea..336e2bc 100644
--- a/lib/js/test/test-async.js
+++ b/lib/js/test/test-async.js
@@ -97,6 +97,7 @@
        QUnit.start();
     });
   });
+  // TODO: add testBinary() 
   asyncTest("Byte", function() {
     expect( 2 );
     QUnit.stop();
diff --git a/lib/js/test/test_handler.js b/lib/js/test/test_handler.js
index 17d22cf..50ac7ac 100644
--- a/lib/js/test/test_handler.js
+++ b/lib/js/test/test_handler.js
@@ -48,6 +48,10 @@
     console.log('testDouble(' + thing + ')');

     result(null, thing);

   },

+  testBinary: function(thing, result) {

+    console.log('testBinary(\'' + thing + '\')');

+    result(null, thing);

+  },

   testStruct: function(thing, result) {

     console.log('testStruct(');

     console.log(thing);

diff --git a/lib/nodejs/test/test_handler.js b/lib/nodejs/test/test_handler.js
index 3de8965..09ff39f 100644
--- a/lib/nodejs/test/test_handler.js
+++ b/lib/nodejs/test/test_handler.js
@@ -48,6 +48,10 @@
     console.log('testDouble(' + thing + ')');
     result(null, thing);
   },
+  testBinary: function(thing, result) {
+    console.log('testBinary(\'' + thing + '\')');
+    result(null, thing);
+  },
   testStruct: function(thing, result) {
     console.log('testStruct(');
     console.log(thing);
diff --git a/lib/nodejs/test/test_handler_promise.js b/lib/nodejs/test/test_handler_promise.js
index 385b04c..cda6558 100644
--- a/lib/nodejs/test/test_handler_promise.js
+++ b/lib/nodejs/test/test_handler_promise.js
@@ -47,6 +47,10 @@
     console.log('testDouble(' + thing + ')');
     return thing;
   },
+  testBinary: function(thing) {
+    console.log('testBinary(\'' + thing + '\')');
+    return thing;
+  },
   testStruct: function(thing) {
     console.log('testStruct(');
     console.log(thing);
diff --git a/lib/nodejs/test/thrift_test_driver.js b/lib/nodejs/test/thrift_test_driver.js
index b1d744b..b8c900b 100644
--- a/lib/nodejs/test/thrift_test_driver.js
+++ b/lib/nodejs/test/thrift_test_driver.js
@@ -171,6 +171,8 @@
   assert.equal(7.012052175215044, response);

 });

 

+// TODO: add testBinary() 

+

 var out = new ttypes.Xtruct({

   string_thing: 'Zero',

   byte_thing: 1,

diff --git a/lib/nodejs/test/thrift_test_driver_promise.js b/lib/nodejs/test/thrift_test_driver_promise.js
index 22175cb..f27ba4c 100644
--- a/lib/nodejs/test/thrift_test_driver_promise.js
+++ b/lib/nodejs/test/thrift_test_driver_promise.js
@@ -202,7 +202,9 @@
   .fail(function() {

     assert(false);

   });

-

+  

+// TODO: add testBinary() 

+  

 var out = new ttypes.Xtruct({

   string_thing: 'Zero',

   byte_thing: 1,

diff --git a/lib/php/test/Test/Thrift/Fixtures.php b/lib/php/test/Test/Thrift/Fixtures.php
index 35fc0d9..d9d487f 100644
--- a/lib/php/test/Test/Thrift/Fixtures.php
+++ b/lib/php/test/Test/Thrift/Fixtures.php
@@ -48,6 +48,8 @@
 
     self::$testArgs['testDouble'] = 3.1415926535898;
 
+	// TODO: add testBinary() call
+	
     self::$testArgs['testByte'] = 0x01;
 
     self::$testArgs['testI32'] = pow( 2, 30 );