THIFT-3645 Add command line args and testBool handler to Lua test server
Client: Test (Lua)
Patch: Nobuaki Sukegawa

This closes #876
diff --git a/test/lua/test_basic_server.lua b/test/lua/test_basic_server.lua
index 9dbf707..864b63d 100644
--- a/test/lua/test_basic_server.lua
+++ b/test/lua/test_basic_server.lua
@@ -17,7 +17,10 @@
 
 require('ThriftTest_ThriftTest')
 require('TSocket')
+require('TBufferedTransport')
 require('TFramedTransport')
+require('TCompactProtocol')
+require('TJsonProtocol')
 require('TBinaryProtocol')
 require('TServer')
 require('liblualongnumber')
@@ -34,6 +37,10 @@
   return str
 end
 
+function TestHandler:testBool(bool)
+  return bool
+end
+
 function TestHandler:testByte(byte)
   return byte
 end
@@ -68,7 +75,24 @@
   end
 end
 
-function testBasicServer()
+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 testBasicServer(rawArgs)
+  local opt = parseArgs(rawArgs)
   -- Handler & Processor
   local handler = TestHandler:new{}
   assert(handler, 'Failed to create handler')
@@ -79,14 +103,23 @@
 
   -- Server Socket
   local socket = TServerSocket:new{
-    port = 9090
+    port = opt.port
   }
   assert(socket, 'Failed to create server socket')
 
   -- Transport & Factory
-  local trans_factory = TFramedTransportFactory:new{}
-  assert(trans_factory, 'Failed to create framed transport factory')
-  local prot_factory = TBinaryProtocolFactory:new{}
+  local transports = {
+    buffered = TBufferedTransportFactory,
+    framed = TFramedTransportFactory,
+  }
+  assert(transports[opt.transport], 'Failed to create framed transport factory')
+  local trans_factory = transports[opt.transport]:new{}
+  local protocols = {
+    binary = TBinaryProtocolFactory,
+    compact = TCompactProtocolFactory,
+    json = TJSONProtocolFactory,
+  }
+  local prot_factory = protocols[opt.protocol]:new{}
   assert(prot_factory, 'Failed to create binary protocol factory')
 
   -- Simple Server
@@ -103,5 +136,5 @@
   server = nil
 end
 
-testBasicServer()
-teardown()
\ No newline at end of file
+testBasicServer(arg)
+teardown()