summaryrefslogtreecommitdiff
path: root/test/haxe
diff options
context:
space:
mode:
authorJens Geyer <jensg@apache.org>2016-03-15 23:04:27 +0200
committerJens Geyer <jensg@apache.org>2016-03-16 09:59:47 +0200
commit1d20a370d25b7154104289bb337ab4375edf19b9 (patch)
treedea68765309e7119b83a0bd59dc153e1dd6a941a /test/haxe
parentaadcf34cbf643b5eff1c771047a05a4c77be9d9e (diff)
downloadthrift-1d20a370d25b7154104289bb337ab4375edf19b9.tar.gz
THRIFT-3742 haxe php cli support
Client: Haxe Patch: Oleksii Prudkyi + minor changes from Jens Geyer This closes #950
Diffstat (limited to 'test/haxe')
-rw-r--r--test/haxe/Makefile.am23
-rw-r--r--test/haxe/php.hxml6
-rw-r--r--test/haxe/src/TestClient.hx68
-rw-r--r--test/haxe/src/TestServer.hx2
-rw-r--r--test/haxe/src/TestServerHandler.hx16
5 files changed, 79 insertions, 36 deletions
diff --git a/test/haxe/Makefile.am b/test/haxe/Makefile.am
index 37ccfc389..6094452f9 100644
--- a/test/haxe/Makefile.am
+++ b/test/haxe/Makefile.am
@@ -22,11 +22,12 @@ THRIFTCMD = $(THRIFT) --gen haxe -r
THRIFTTEST = $(top_srcdir)/test/ThriftTest.thrift
BIN_CPP = bin/Main-debug
+BIN_PHP = bin/php/Main-debug.php
gen-haxe/thrift/test/ThriftTest.hx: $(THRIFTTEST)
$(THRIFTCMD) $(THRIFTTEST)
-all-local: $(BIN_CPP)
+all-local: $(BIN_CPP) $(BIN_PHP)
$(BIN_CPP): \
src/*.hx \
@@ -34,6 +35,14 @@ $(BIN_CPP): \
gen-haxe/thrift/test/ThriftTest.hx
$(HAXE) --cwd . cpp.hxml
+$(BIN_PHP): \
+ src/*.hx \
+ ../../lib/haxe/src/org/apache/thrift/**/*.hx \
+ gen-haxe/thrift/test/ThriftTest.hx
+ $(HAXE) --cwd . php.hxml
+
+
+
#TODO: other haxe targets
# $(HAXE) --cwd . csharp
@@ -41,19 +50,27 @@ $(BIN_CPP): \
# $(HAXE) --cwd . java
# $(HAXE) --cwd . javascript
# $(HAXE) --cwd . neko
-# $(HAXE) --cwd . php
# $(HAXE) --cwd . python # needs Haxe 3.2.0
clean-local:
$(RM) -r gen-haxe bin
-check: $(BIN_CPP)
+check: check_cpp check_php
+
+check_cpp: $(BIN_CPP)
timeout 10 $(BIN_CPP) server &
sleep 1
$(BIN_CPP) client
sleep 10
+check_php: $(BIN_PHP)
+ timeout 10 php -f $(BIN_PHP) server &
+ sleep 1
+ php -f $(BIN_PHP) client
+ sleep 10
+
+
EXTRA_DIST = \
src \
cpp.hxml \
diff --git a/test/haxe/php.hxml b/test/haxe/php.hxml
index 1eaac8b2b..965189843 100644
--- a/test/haxe/php.hxml
+++ b/test/haxe/php.hxml
@@ -26,7 +26,9 @@
-main Main
#PHP target
--php bin/Tutorial.php
+-php bin/php/
+--php-front Main-debug.php
+
#Add debug information
-debug
@@ -35,4 +37,4 @@
#"-dce no" : do not remove unused code
#"-dce std" : remove unused code in the std lib (default)
#"-dce full" : remove all unused code
--dce full \ No newline at end of file
+-dce full
diff --git a/test/haxe/src/TestClient.hx b/test/haxe/src/TestClient.hx
index 5c0de7c76..ee1f01940 100644
--- a/test/haxe/src/TestClient.hx
+++ b/test/haxe/src/TestClient.hx
@@ -43,6 +43,8 @@ import cpp.vm.Thread;
import thrift.test.*; // generated code
+using StringTools;
+
class TestResults {
private var successCnt : Int = 0;
private var errorCnt : Int = 0;
@@ -102,7 +104,7 @@ class TestResults {
if ( errorCnt > 0)
{
trace('===========================');
- trace('FAILED TESTS: $failedTests');
+ trace('FAILED TESTS: $failedTests');
}
trace('===========================');
}
@@ -118,20 +120,15 @@ class TestClient {
{
var difft = Timer.stamp();
- if( args.numThreads > 1) {
- var threads = new List<Thread>();
- for( test in 0 ... args.numThreads) {
- threads.add( StartThread( args));
- }
- exitCode = 0;
- for( thread in threads) {
- exitCode |= Thread.readMessage(true);
- }
+ if ( args.numThreads > 1) {
+ #if cpp
+ exitCode = MultiThreadClient(args);
+ #else
+ trace('Threads not supported/implemented for this platform.');
+ exitCode = SingleThreadClient(args);
+ #end
} else {
- var rslt = new TestResults(true);
- RunClient(args,rslt);
- rslt.PrintSummary();
- exitCode = rslt.CalculateExitCode();
+ exitCode = SingleThreadClient(args);
}
difft = Math.round( 1000 * (Timer.stamp() - difft)) / 1000;
@@ -154,6 +151,31 @@ class TestClient {
}
+ public static function SingleThreadClient(args : Arguments) : Int
+ {
+ var rslt = new TestResults(true);
+ RunClient(args,rslt);
+ rslt.PrintSummary();
+ return rslt.CalculateExitCode();
+ }
+
+
+ #if cpp
+ public static function MultiThreadClient(args : Arguments) : Int
+ {
+ var threads = new List<Thread>();
+ for( test in 0 ... args.numThreads) {
+ threads.add( StartThread( args));
+ }
+ var exitCode : Int = 0;
+ for( thread in threads) {
+ exitCode |= Thread.readMessage(true);
+ }
+ return exitCode;
+ }
+ #end
+
+ #if cpp
private static function StartThread(args : Arguments) : Thread {
var thread = Thread.create(
function() : Void {
@@ -179,6 +201,7 @@ class TestClient {
thread.sendMessage(Thread.current());
return thread;
}
+ #end
public static function RunClient(args : Arguments, rslt : TestResults)
@@ -297,8 +320,9 @@ class TestClient {
rslt.Expect( c32 == c64, "Int64Map<Int32> Test #30");
rslt.Expect( '$ksum64' == '$ksum32', '$ksum64 == $ksum32 Test #31');
- var s32 = map32.toString();
- var s64 = map64.toString();
+ //compare without spaces because differ in php and cpp
+ var s32 = map32.toString().replace(' ', '');
+ var s64 = map64.toString().replace(' ', '');
rslt.Expect( s32 == s64, "Int64Map<Int32>.toString(): " + ' ("$s32" == "$s64") Test #32');
map32.remove( 42);
@@ -322,8 +346,8 @@ class TestClient {
// core module unit tests
public static function ModuleUnitTests( args : Arguments, rslt : TestResults) : Void {
- #if debug
-
+ #if debug
+
try {
BitConverter.UnitTest();
rslt.Expect( true, 'BitConverter.UnitTest Test #100');
@@ -339,8 +363,8 @@ class TestClient {
catch( e : Dynamic) {
rslt.Expect( false, 'ZigZag.UnitTest: $e Test #101');
}
-
- #end
+
+ #end
}
@@ -464,11 +488,11 @@ class TestClient {
trace('testBool(${true})');
var b = client.testBool(true);
trace(' = $b');
- rslt.Expect(b, '$b == "${true}"');
+ rslt.Expect(b, '$b == "${true}"');
trace('testBool(${false})');
b = client.testBool(false);
trace(' = $b');
- rslt.Expect( ! b, '$b == "${false}"');
+ rslt.Expect( ! b, '$b == "${false}"');
trace('testString("Test")');
var s = client.testString("Test");
diff --git a/test/haxe/src/TestServer.hx b/test/haxe/src/TestServer.hx
index bff5a47ab..8f4604a6e 100644
--- a/test/haxe/src/TestServer.hx
+++ b/test/haxe/src/TestServer.hx
@@ -106,7 +106,7 @@ class TestServer
}
catch (x : TException)
{
- trace('$x ${x.errorID} ${x.errorMsg}');
+ trace('$x ${x.errorID} ${x.errorMsg}');
}
catch (x : Dynamic)
{
diff --git a/test/haxe/src/TestServerHandler.hx b/test/haxe/src/TestServerHandler.hx
index 74a8805d4..9fba1360b 100644
--- a/test/haxe/src/TestServerHandler.hx
+++ b/test/haxe/src/TestServerHandler.hx
@@ -51,14 +51,14 @@ class TestServerHandler implements ThriftTest {
trace("testVoid()");
}
- /**
- * Prints 'testBool("%s")' where '%s' with thing as 'true' or 'false'
- * @param bool thing - the bool data to print
- * @return bool - returns the bool 'thing'
- *
- * @param thing
- */
- public function testBool(thing : Bool) : Bool
+ /**
+ * Prints 'testBool("%s")' where '%s' with thing as 'true' or 'false'
+ * @param bool thing - the bool data to print
+ * @return bool - returns the bool 'thing'
+ *
+ * @param thing
+ */
+ public function testBool(thing : Bool) : Bool
{
trace('testBool($thing)');
return thing;