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/test/c_glib/src/test_client.c b/test/c_glib/src/test_client.c
index 59f4157..dba2daf 100644
--- a/test/c_glib/src/test_client.c
+++ b/test/c_glib/src/test_client.c
@@ -379,6 +379,8 @@
fail_count++;
}
+ // TODO: add testBinary()
+
/**
* STRUCT TEST
*/
diff --git a/test/c_glib/src/thrift_test_handler.c b/test/c_glib/src/thrift_test_handler.c
index 596e615..ae273bf 100644
--- a/test/c_glib/src/thrift_test_handler.c
+++ b/test/c_glib/src/thrift_test_handler.c
@@ -119,6 +119,21 @@
return TRUE;
}
+gboolean
+thrift_test_handler_test_binary (TTestThriftTestIf *iface,
+ GByteArray ** _return,
+ const GByteArray * thing,
+ GError **error)
+{
+ THRIFT_UNUSED_VAR (iface);
+ THRIFT_UNUSED_VAR (error);
+
+ printf ("testBinary()\n"); // TODO: hex output
+ g_byte_array_append( *_return, thing->data, thing->len);
+
+ return TRUE;
+}
+
gboolean
thrift_test_handler_test_struct (TTestThriftTestIf *iface,
TTestXtruct **_return,
diff --git a/test/cpp/src/TestClient.cpp b/test/cpp/src/TestClient.cpp
index a6069de..c496bcb 100644
--- a/test/cpp/src/TestClient.cpp
+++ b/test/cpp/src/TestClient.cpp
@@ -334,6 +334,7 @@
printf(" = %" PRId64 "\n", i64);
if (i64 != -34359738368LL)
failCount++;
+
/**
* DOUBLE TEST
*/
@@ -344,6 +345,11 @@
failCount++;
/**
+ * BINARY TEST
+ */
+ // TODO: add testBinary() call
+
+ /**
* STRUCT TEST
*/
printf("testStruct({\"Zero\", 1, -3, -5})");
diff --git a/test/cpp/src/TestServer.cpp b/test/cpp/src/TestServer.cpp
index 6d2a260..2705064 100644
--- a/test/cpp/src/TestServer.cpp
+++ b/test/cpp/src/TestServer.cpp
@@ -98,6 +98,13 @@
return thing;
}
+ void testBinary(std::string& _return, const std::string& thing) {
+ std::ostringstream hexstr;
+ hexstr << std::hex << thing;
+ printf("testBinary(%s)\n", hexstr.str().c_str());
+ _return = thing;
+ }
+
void testStruct(Xtruct& out, const Xtruct& thing) {
printf("testStruct({\"%s\", %d, %d, %" PRId64 "})\n",
thing.string_thing.c_str(),
@@ -411,6 +418,12 @@
cob(res);
}
+ virtual void testBinary(tcxx::function<void(std::string const& _return)> cob, const std::string& thing) {
+ std::string res;
+ _delegate->testBinary(res, thing);
+ cob(res);
+ }
+
virtual void testStruct(tcxx::function<void(Xtruct const& _return)> cob, const Xtruct& thing) {
Xtruct res;
_delegate->testStruct(res, thing);
diff --git a/test/go/src/bin/testclient/main.go b/test/go/src/bin/testclient/main.go
index 2acf6cf..c48df0e 100644
--- a/test/go/src/bin/testclient/main.go
+++ b/test/go/src/bin/testclient/main.go
@@ -107,6 +107,8 @@
t.Fatalf("Unexpected TestDouble() result expected 42.42, got %f ", d)
}
+ // TODO: add TestBinary() call
+
xs := thrifttest.NewXtruct()
xs.StringThing = "thing"
xs.ByteThing = 42
diff --git a/test/go/src/common/clientserver_test.go b/test/go/src/common/clientserver_test.go
index 8add041..3b512ad 100644
--- a/test/go/src/common/clientserver_test.go
+++ b/test/go/src/common/clientserver_test.go
@@ -92,6 +92,7 @@
handler.EXPECT().TestByte(int8(42)).Return(int8(42), nil),
handler.EXPECT().TestI32(int32(4242)).Return(int32(4242), nil),
handler.EXPECT().TestI64(int64(424242)).Return(int64(424242), nil),
+ // TODO: add TestBinary()
handler.EXPECT().TestDouble(float64(42.42)).Return(float64(42.42), nil),
handler.EXPECT().TestStruct(&thrifttest.Xtruct{StringThing: "thing", ByteThing: 42, I32Thing: 4242, I64Thing: 424242}).Return(&thrifttest.Xtruct{StringThing: "thing", ByteThing: 42, I32Thing: 4242, I64Thing: 424242}, nil),
handler.EXPECT().TestNest(&thrifttest.Xtruct2{StructThing: &thrifttest.Xtruct{StringThing: "thing", ByteThing: 42, I32Thing: 4242, I64Thing: 424242}}).Return(&thrifttest.Xtruct2{StructThing: &thrifttest.Xtruct{StringThing: "thing", ByteThing: 42, I32Thing: 4242, I64Thing: 424242}}, nil),
@@ -156,6 +157,8 @@
t.Errorf("Unexpected TestDouble() result expected 42.42, got %f ", d)
}
+ // TODO: add TestBinary() call
+
xs := thrifttest.NewXtruct()
xs.StringThing = "thing"
xs.ByteThing = 42
diff --git a/test/go/src/common/mock_handler.go b/test/go/src/common/mock_handler.go
index d736ed9..8ef3b6e 100644
--- a/test/go/src/common/mock_handler.go
+++ b/test/go/src/common/mock_handler.go
@@ -70,6 +70,17 @@
return _mr.mock.ctrl.RecordCall(_mr.mock, "TestDouble", arg0)
}
+func (_m *MockThriftTest) TestBinary(_param0 []byte) ([]byte, error) {
+ ret := _m.ctrl.Call(_m, "TestBinary", _param0)
+ ret0, _ := ret[0].([]byte)
+ ret1, _ := ret[1].(error)
+ return ret0, ret1
+}
+
+func (_mr *_MockThriftTestRecorder) TestBinary(arg0 interface{}) *gomock.Call {
+ return _mr.mock.ctrl.RecordCall(_mr.mock, "TestBinary", arg0)
+}
+
func (_m *MockThriftTest) TestEnum(_param0 thrifttest.Numberz) (thrifttest.Numberz, error) {
ret := _m.ctrl.Call(_m, "TestEnum", _param0)
ret0, _ := ret[0].(thrifttest.Numberz)
diff --git a/test/go/src/common/printing_handler.go b/test/go/src/common/printing_handler.go
index 6cc1507..bed7086 100644
--- a/test/go/src/common/printing_handler.go
+++ b/test/go/src/common/printing_handler.go
@@ -22,6 +22,7 @@
import (
"errors"
"fmt"
+ "encoding/hex"
. "gen/thrifttest"
"time"
)
@@ -91,6 +92,17 @@
return thing, nil
}
+// Prints 'testBinary("%s")' where '%s' is a hex-formatted string of thing's data
+// @param []byte thing - the binary to print
+// @return []byte - returns the binary 'thing'
+//
+// Parameters:
+// - Thing
+func (p *printingHandler) TestBinary(thing []byte) (r []byte, err error) {
+ fmt.Printf("testBinary(%s)\n", hex.EncodeToString(thing))
+ return thing, nil
+}
+
// Prints 'testStruct("{%s}")' where thing has been formatted into a string of comma separated values
// @param Xtruct thing - the Xtruct to print
// @return Xtruct - returns the Xtruct 'thing'
diff --git a/test/go/src/common/simple_handler.go b/test/go/src/common/simple_handler.go
index 433616d..97ff52d 100644
--- a/test/go/src/common/simple_handler.go
+++ b/test/go/src/common/simple_handler.go
@@ -53,6 +53,10 @@
return thing, nil
}
+func (p *simpleHandler) TestBinary(thing []byte) (r []byte, err error) {
+ return thing, nil
+}
+
func (p *simpleHandler) TestStruct(thing *Xtruct) (r *Xtruct, err error) {
return r, err
}
diff --git a/test/hs/TestClient.hs b/test/hs/TestClient.hs
index 03314ed..6c25f5b 100644
--- a/test/hs/TestClient.hs
+++ b/test/hs/TestClient.hs
@@ -105,6 +105,8 @@
dub <- Client.testDouble prot (-5.2098523)
when (abs (dub + 5.2098523) > 0.001) exitFailure
+ -- TODO: call Client.testBinary
+
-- Struct Test
let structIn = Xtruct{ xtruct_string_thing = "Zero"
, xtruct_byte_thing = 1
diff --git a/test/hs/TestServer.hs b/test/hs/TestServer.hs
index ec3891c..d991de1 100755
--- a/test/hs/TestServer.hs
+++ b/test/hs/TestServer.hs
@@ -127,6 +127,10 @@
System.IO.putStrLn $ "testDouble(" ++ show x ++ ")"
return x
+ testBinary _ x = do
+ System.IO.putStrLn $ "testBinary(" ++ show x ++ ")"
+ return x
+
testStruct _ struct@Xtruct{..} = do
System.IO.putStrLn $ "testStruct({" ++ show xtruct_string_thing
++ ", " ++ show xtruct_byte_thing
diff --git a/test/hs/ThriftTest_Main.hs b/test/hs/ThriftTest_Main.hs
index 1139506..670023e 100755
--- a/test/hs/ThriftTest_Main.hs
+++ b/test/hs/ThriftTest_Main.hs
@@ -67,6 +67,10 @@
ThriftTestUtils.serverLog $ show x
return x
+ testBinary _ x = do
+ ThriftTestUtils.serverLog $ show x
+ return x
+
testStruct _ x = do
ThriftTestUtils.serverLog $ show x
return x
@@ -150,6 +154,8 @@
v9 <- Client.testDouble ps (-3.14)
ThriftTestUtils.clientLog $ show v9
+ -- TODO: Client.testBinary ...
+
v10 <- Client.testMap ps (Map.fromList [(1,1),(2,2),(3,3)])
ThriftTestUtils.clientLog $ show v10
diff --git a/test/lua/test_basic_client.lua b/test/lua/test_basic_client.lua
index e2e0d48..e7571f9 100644
--- a/test/lua/test_basic_client.lua
+++ b/test/lua/test_basic_client.lua
@@ -112,6 +112,8 @@
assertEqual(
client:testDouble(0.123456789), 0.123456789, 'Failed testDouble 3')
+ -- TODO testBinary() ...
+
-- Accuracy of 16 decimal digits (rounds)
local a, b = 1.12345678906666663, 1.12345678906666661
assertEqual(a, b)
diff --git a/test/lua/test_basic_server.lua b/test/lua/test_basic_server.lua
index 7c175da..96a1ae9 100644
--- a/test/lua/test_basic_server.lua
+++ b/test/lua/test_basic_server.lua
@@ -51,6 +51,10 @@
return d
end
+function TestHandler:testBinary(by)
+ return by
+end
+
function TestHandler:testStruct(thing)
return thing
end
diff --git a/test/ocaml/server/TestServer.ml b/test/ocaml/server/TestServer.ml
index 3f5c9ee..efe0f4b 100644
--- a/test/ocaml/server/TestServer.ml
+++ b/test/ocaml/server/TestServer.ml
@@ -36,6 +36,7 @@
method testI32 x = p "testI32(%d)\n" (sod x); (sod x)
method testI64 x = p "testI64(%s)\n" (Int64.to_string (sod x)); (sod x)
method testDouble x = p "testDouble(%f)\n" (sod x); (sod x)
+ method testBinary x = p "testBinary(%s)\n" (sod x); (sod x)
method testStruct x = p "testStruct(---)\n"; (sod x)
method testNest x = p "testNest(---)\n"; (sod x)
method testMap x = p "testMap(---)\n"; (sod x)
diff --git a/test/perl/TestClient.pl b/test/perl/TestClient.pl
index af80d46..ca1d47e 100644
--- a/test/perl/TestClient.pl
+++ b/test/perl/TestClient.pl
@@ -99,6 +99,11 @@
print(" = $dub\n");
#
+# BINARY TEST --- TODO
+#
+
+
+#
# STRUCT TEST
#
print("testStruct({\"Zero\", 1, -3, -5})");
diff --git a/test/php/TestClient.php b/test/php/TestClient.php
index c334aee..ea17435 100755
--- a/test/php/TestClient.php
+++ b/test/php/TestClient.php
@@ -128,6 +128,10 @@
print_r(" = $dub\n");
/**
+ * BINARY TEST -- TODO
+ */
+
+/**
* STRUCT TEST
*/
print_r("testStruct({\"Zero\", 1, -3, -5})");
diff --git a/test/py.tornado/test_suite.py b/test/py.tornado/test_suite.py
index c783962..b63ea2d 100755
--- a/test/py.tornado/test_suite.py
+++ b/test/py.tornado/test_suite.py
@@ -72,6 +72,9 @@
def testDouble(self, dub):
return dub
+ def testBinary(self, thing):
+ return thing
+
def testStruct(self, thing):
return thing
diff --git a/test/py.twisted/test_suite.py b/test/py.twisted/test_suite.py
index 6e1fee2..26c1ee2 100644
--- a/test/py.twisted/test_suite.py
+++ b/test/py.twisted/test_suite.py
@@ -59,6 +59,9 @@
def testDouble(self, dub):
return dub
+ def testBinary(self, thing):
+ return thing
+
def testStruct(self, thing):
return thing
@@ -144,6 +147,8 @@
def testDouble(self):
self.assertEquals((yield self.client.testDouble(-5.235098235)), -5.235098235)
+ # TODO: def testBinary(self) ...
+
@defer.inlineCallbacks
def testStruct(self):
x = Xtruct()
diff --git a/test/py/TestClient.py b/test/py/TestClient.py
index 87fede6..a810b3f 100755
--- a/test/py/TestClient.py
+++ b/test/py/TestClient.py
@@ -118,6 +118,8 @@
self.assertEqual(self.client.testDouble(0), 0)
self.assertEqual(self.client.testDouble(-1), -1)
+ # TODO: def testBinary(self) ...
+
def testStruct(self):
x = Xtruct()
x.string_thing = "Zero"
diff --git a/test/py/TestServer.py b/test/py/TestServer.py
index 820b816..b29eabd 100755
--- a/test/py/TestServer.py
+++ b/test/py/TestServer.py
@@ -101,6 +101,11 @@
print 'testDouble(%f)' % dub
return dub
+ def testBinary(self, thing):
+ if options.verbose > 1:
+ print 'testBinary()' # TODO: hex output
+ return thring
+
def testStruct(self, thing):
if options.verbose > 1:
print 'testStruct({%s, %d, %d, %d})' % (thing.string_thing, thing.byte_thing, thing.i32_thing, thing.i64_thing)
diff --git a/test/rb/integration/TestClient.rb b/test/rb/integration/TestClient.rb
index 41625a8..3659ccb 100755
--- a/test/rb/integration/TestClient.rb
+++ b/test/rb/integration/TestClient.rb
@@ -116,6 +116,8 @@
assert_kind_of(Float, @client.testDouble(val))
end
+ # TODO: testBinary
+
def test_map
val = {1 => 1, 2 => 2, 3 => 3}
assert_equal(@client.testMap(val), val)
diff --git a/test/rb/integration/TestServer.rb b/test/rb/integration/TestServer.rb
index 3e365ca..64949bc 100755
--- a/test/rb/integration/TestServer.rb
+++ b/test/rb/integration/TestServer.rb
@@ -26,7 +26,7 @@
require 'thrift_test'
class SimpleHandler
- [:testVoid, :testString, :testByte, :testI32, :testI64, :testDouble,
+ [:testVoid, :testString, :testByte, :testI32, :testI64, :testDouble, :testBinary,
:testStruct, :testMap, :testSet, :testList, :testNest,
:testEnum, :testTypedef, :testMultiException].each do |meth|