THRIFT-2753 Haxe support: Misc. improvements
Client: Haxe
Patch: Jens Geyer
This closes #229
diff --git a/lib/haxe/test/src/Main.hx b/lib/haxe/test/src/Main.hx
new file mode 100644
index 0000000..fff8be5
--- /dev/null
+++ b/lib/haxe/test/src/Main.hx
@@ -0,0 +1,45 @@
+/*
+ * 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.
+ */
+
+package;
+
+import org.apache.thrift.*;
+import org.apache.thrift.protocol.*;
+import org.apache.thrift.transport.*;
+import org.apache.thrift.server.*;
+import org.apache.thrift.meta_data.*;
+
+import thrift.test.*; // generated code
+
+class Main
+{
+ static public function main()
+ {
+ try
+ {
+ StreamTest.Run();
+
+ trace("All tests completed.");
+ }
+ catch( e: Dynamic)
+ {
+ trace('$e');
+ }
+ }
+}
\ No newline at end of file
diff --git a/lib/haxe/test/src/StreamTest.hx b/lib/haxe/test/src/StreamTest.hx
new file mode 100644
index 0000000..b28c8e9
--- /dev/null
+++ b/lib/haxe/test/src/StreamTest.hx
@@ -0,0 +1,93 @@
+/*
+ * 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.
+ */
+
+package;
+
+import haxe.Int64;
+
+import org.apache.thrift.*;
+import org.apache.thrift.protocol.*;
+import org.apache.thrift.transport.*;
+import org.apache.thrift.server.*;
+import org.apache.thrift.meta_data.*;
+
+import thrift.test.*; // generated code
+
+
+class StreamTest extends TestBase {
+
+
+ private inline static var tmpfile : String = "bin/data.tmp";
+
+
+ private static function Expect( expr : Bool, info : String, ?pos : haxe.PosInfos) : Void {
+ if( ! expr) {
+ throw ('Test "$info" failed at '+pos.methodName+' in '+pos.fileName+':'+pos.lineNumber);
+ }
+ }
+
+ private static function MakeTestData() : Xtruct {
+ var data : Xtruct = new Xtruct();
+ data.string_thing = "Streamtest";
+ data.byte_thing = -128;
+ data.i32_thing = 4711;
+ data.i64_thing = Int64.make(0x12345678,0x9ABCDEF0);
+ return data;
+ }
+
+ public static function WriteData() : Xtruct
+ {
+ var stream : TStream = new TFileStream( tmpfile, CreateNew);
+ var trans : TTransport = new TStreamTransport( null, stream);
+ var prot = new TJSONProtocol( trans);
+
+ var data = MakeTestData();
+ data.write(prot);
+ trans.close();
+
+ return data;
+ }
+
+ public static function ReadData() : Xtruct
+ {
+ var stream : TStream = new TFileStream( tmpfile, Read);
+ var trans : TTransport = new TStreamTransport( stream, null);
+ var prot = new TJSONProtocol( trans);
+
+ var data : Xtruct = new Xtruct();
+ data.read(prot);
+ trans.close();
+
+ return data;
+ }
+
+ public static override function Run() : Void
+ {
+ var written = WriteData();
+ var read = ReadData();
+
+ Expect( read.string_thing == written.string_thing, "string data");
+ Expect( read.byte_thing == written.byte_thing, "byte data");
+ Expect( read.i32_thing == written.i32_thing, "i32 data");
+ Expect( Int64.compare( read.i64_thing, written.i64_thing) == 0, "i64 data");
+ }
+
+}
+
+
diff --git a/lib/haxe/test/src/TestBase.hx b/lib/haxe/test/src/TestBase.hx
new file mode 100644
index 0000000..03b66dd
--- /dev/null
+++ b/lib/haxe/test/src/TestBase.hx
@@ -0,0 +1,39 @@
+/*
+ * 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.
+ */
+
+package;
+
+import org.apache.thrift.*;
+import org.apache.thrift.protocol.*;
+import org.apache.thrift.transport.*;
+import org.apache.thrift.server.*;
+import org.apache.thrift.meta_data.*;
+
+import thrift.test.*; // generated code
+
+class TestBase {
+
+ private function new() {
+ // override, if necessary
+ }
+
+ public static function Run() : Void {
+ throw new AbstractMethodError();
+ }
+}