summaryrefslogtreecommitdiff
path: root/test/lua
diff options
context:
space:
mode:
authorNobuaki Sukegawa <nsuke@apache.org>2016-02-01 21:47:49 +0900
committerNobuaki Sukegawa <nsuke@apache.org>2016-02-03 01:07:43 +0900
commitd094e79de7e0bd61320f006c83c0de669363bce8 (patch)
tree77b87a8ca65e965b7b95d65d5dc8c02ee04dbdcd /test/lua
parentf07b4a14dfc30a397d49b18c3f50230a08310bd1 (diff)
downloadthrift-d094e79de7e0bd61320f006c83c0de669363bce8.tar.gz
THRIFT-3592 Add basic test client
This closes #830
Diffstat (limited to 'test/lua')
-rw-r--r--test/lua/Makefile.am30
-rw-r--r--test/lua/test_basic_client.lua53
-rw-r--r--test/lua/test_basic_server.lua1
3 files changed, 73 insertions, 11 deletions
diff --git a/test/lua/Makefile.am b/test/lua/Makefile.am
new file mode 100644
index 000000000..91de535be
--- /dev/null
+++ b/test/lua/Makefile.am
@@ -0,0 +1,30 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+
+THRIFT = $(top_builddir)/compiler/cpp/thrift
+
+# Remove "MapType =" line to ignore some map bug for now
+stubs: ../ThriftTest.thrift $(THRIFT)
+ $(THRIFT) --gen lua $<
+ $(SED) -i 's/MapType =//g' gen-lua/ThriftTest_ttypes.lua
+
+precross: stubs
+
+clean-local:
+ $(RM) -r gen-lua
diff --git a/test/lua/test_basic_client.lua b/test/lua/test_basic_client.lua
index e7571f939..5e0966fc1 100644
--- a/test/lua/test_basic_client.lua
+++ b/test/lua/test_basic_client.lua
@@ -17,6 +17,8 @@
require('TSocket')
+require('TBufferedTransport')
+require('TFramedTransport')
require('TBinaryProtocol')
require('ThriftTest_ThriftTest')
require('liblualongnumber')
@@ -25,28 +27,56 @@ local client
function teardown()
if client then
- -- Shuts down the server
- client:testVoid()
-
-- close the connection
client:close()
end
end
+function parseArgs(rawArgs)
+ local opt = {
+ protocol='binary',
+ transport='buffered',
+ port='9090',
+ }
+ for i, str in pairs(rawArgs) do
+ if i > 0 then
+ k, v = string.match(str, '--(%w+)=(%w+)')
+ assert(opt[k] ~= nil, 'Unknown argument')
+ opt[k] = v
+ end
+ end
+ return opt
+end
+
function assertEqual(val1, val2, msg)
assert(val1 == val2, msg)
end
-function testBasicClient()
+function testBasicClient(rawArgs)
+ local opt = parseArgs(rawArgs)
local socket = TSocket:new{
- port = 9090
+ port = tonumber(opt.port)
}
assert(socket, 'Failed to create client socket')
socket:setTimeout(5000)
- local protocol = TBinaryProtocol:new{
+ local transports = {
+ buffered = TBufferedTransport,
+ framed = TFramedTransport,
+ }
+ assert(transports[opt.transport] ~= nil)
+ local transport = transports[opt.transport]:new{
trans = socket
}
+
+ local protocols = {
+ binary = TBinaryProtocol,
+ -- compact = TCompactProtocol,
+ }
+ assert(protocols[opt.protocol] ~= nil)
+ local protocol = protocols[opt.protocol]:new{
+ trans = transport
+ }
assert(protocol, 'Failed to create binary protocol')
client = ThriftTestClient:new{
@@ -62,6 +92,10 @@ function testBasicClient()
assertEqual(client:testString('lala'), 'lala', 'Failed testString')
assertEqual(client:testString('wahoo'), 'wahoo', 'Failed testString')
+ -- Bool
+ assertEqual(client:testBool(true), true, 'Failed testBool true')
+ -- assertEqual(client:testBool(false), false, 'Failed testBool false')
+
-- Byte
assertEqual(client:testByte(0x01), 1, 'Failed testByte 1')
assertEqual(client:testByte(0x40), 64, 'Failed testByte 2')
@@ -130,9 +164,8 @@ function testBasicClient()
-- TODO fix client struct equality
--assertEqual(client:testStruct(a), a, 'Failed testStruct')
- -- Call the void function and end the test (handler stops server)
- client:testVoid()
+ -- TODO add list map set exception etc etc
end
-testBasicClient()
-teardown() \ No newline at end of file
+testBasicClient(arg)
+teardown()
diff --git a/test/lua/test_basic_server.lua b/test/lua/test_basic_server.lua
index 96a1ae9e0..fb8f074d4 100644
--- a/test/lua/test_basic_server.lua
+++ b/test/lua/test_basic_server.lua
@@ -28,7 +28,6 @@ TestHandler = ThriftTestIface:new{}
-- Stops the server
function TestHandler:testVoid()
- self.__server:stop()
end
function TestHandler:testString(str)