Protocol conformity and serialization tests for UUIDs - Haxe
diff --git a/lib/haxe/src/org/apache/thrift/TConfiguration.hx b/lib/haxe/src/org/apache/thrift/TConfiguration.hx
index 47973f2..3bc5a86 100644
--- a/lib/haxe/src/org/apache/thrift/TConfiguration.hx
+++ b/lib/haxe/src/org/apache/thrift/TConfiguration.hx
@@ -25,9 +25,9 @@
 	public static inline var DEFAULT_MAX_FRAME_SIZE = 16384000;      // this value is used consistently across all Thrift libraries
 	public static inline var DEFAULT_RECURSION_DEPTH = 64;
 
-	public var MaxMessageSize(default,null) : Int = DEFAULT_MAX_MESSAGE_SIZE;
-	public var MaxFrameSize(default,null) : Int = DEFAULT_MAX_FRAME_SIZE;
-	public var RecursionLimit(default,null) : Int = DEFAULT_RECURSION_DEPTH;
+	public var MaxMessageSize(default,default) : Int = DEFAULT_MAX_MESSAGE_SIZE;
+	public var MaxFrameSize(default,default) : Int = DEFAULT_MAX_FRAME_SIZE;
+	public var RecursionLimit(default,default) : Int = DEFAULT_RECURSION_DEPTH;
 
 	// TODO(JensG): add connection and i/o timeouts
 	
diff --git a/lib/haxe/test/HaxeTests.hxproj b/lib/haxe/test/HaxeTests.hxproj
index 839917b..fbb9c8e 100644
--- a/lib/haxe/test/HaxeTests.hxproj
+++ b/lib/haxe/test/HaxeTests.hxproj
@@ -63,7 +63,7 @@
   <options>
     <option showHiddenPaths="False" />
     <option testMovie="Custom" />
-    <option testMovieCommand="bin/HaxeTests/Main.exe server multiplex" />
+    <option testMovieCommand="bin/HaxeTests/Main.exe server constants" />
   </options>
   <!-- Plugin storage -->
   <storage />
diff --git a/lib/haxe/test/src/ConstantsTest.hx b/lib/haxe/test/src/ConstantsTest.hx
deleted file mode 100644
index d0041e4..0000000
--- a/lib/haxe/test/src/ConstantsTest.hx
+++ /dev/null
@@ -1,74 +0,0 @@
-/*
- * 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 constantsDemo.*;  // generated code
-
-
-class ConstantsTest extends TestBase {
-
-    public static function Run(server : Bool) : Void
-    {
-        TestBase.Expect( ConstantsDemoConstants.myInt == 3, "myInt = 3");
-        TestBase.Expect( ConstantsDemoConstants.hex_const == 0x0001F, "hex_const = 31");
-        TestBase.Expect( ConstantsDemoConstants.negative_hex_constant == -0x0001F, "negative_hex_constant = -31");
-        TestBase.Expect( ConstantsDemoConstants.GEN_ME == -3523553, "GEN_ME = -3523553");
-        TestBase.Expect( ConstantsDemoConstants.GEn_DUB == 325.532, "GEn_DUB = 325.532");
-        TestBase.Expect( ConstantsDemoConstants.GEn_DU == 85.2355, "GEn_DU = 85.2355");
-        TestBase.Expect( ConstantsDemoConstants.GEN_STRING == "asldkjasfd", "GEN_STRING = \"asldkjasfd\"");
-        TestBase.Expect( ConstantsDemoConstants.e10 == 1e+10, "e10 = 1e+10");
-        TestBase.Expect( ConstantsDemoConstants.e11 == -1e+10, "e11 = -1e+10");
-        TestBase.Expect( ConstantsDemoConstants.GEN_UUID == "00000000-4444-CCCC-ffff-0123456789ab", "GEN_UUID = \"00000000-4444-CCCC-ffff-0123456789ab\"");
-
-        TestBase.Expect( ConstantsDemoConstants.GEN_MAP.get(35532) == 233, "GEN_MAP.get(35532) == 233");
-        TestBase.Expect( ConstantsDemoConstants.GEN_MAP.get(43523) == 853, "GEN_MAP.get(43523) == 853");
-        
-        TestBase.Expect( ConstantsDemoConstants.GEN_LIST.length == 3, "GEN_LIST.size() == 3");
-        TestBase.Expect( ConstantsDemoConstants.GEN_LIST.join("/") == "235235/23598352/3253523", "GEN_LIST elements");
-
-        TestBase.Expect( ConstantsDemoConstants.GEN_MAPMAP.get(235).get(532) == 53255, "GEN_MAPMAP.get(235).get(532) == 53255");
-        TestBase.Expect( ConstantsDemoConstants.GEN_MAPMAP.get(235).get(235) == 235, "GEN_MAPMAP.get(235).get(235) == 235");
-
-        TestBase.Expect( ConstantsDemoConstants.GEN_MAP2.get("hello") == 233, "GEN_MAP2.get(\"hello\") == 233");
-        TestBase.Expect( ConstantsDemoConstants.GEN_MAP2.get("lkj98d") == 853, "GEN_MAP2.get(\"lkj98d\") == 853");
-        TestBase.Expect( ConstantsDemoConstants.GEN_MAP2.get('lkjsdf') == 98325, "GEN_MAP2.get('lkjsdf') == 98325");
-        
-        TestBase.Expect( ConstantsDemoConstants.GEN_THING.hello == 325, "GEN_THING.hello == 325");
-        TestBase.Expect( ConstantsDemoConstants.GEN_THING.goodbye == 325352, "GEN_THING.goodbye == 325352");
-
-        TestBase.Expect( ConstantsDemoConstants.GEN_WHAT.get(35).hello == 325, "GEN_WHAT.get(35).hello == 325");
-        TestBase.Expect( ConstantsDemoConstants.GEN_WHAT.get(35).goodbye == 325352, "GEN_WHAT.get(35).goodbye == 325352");
-
-        TestBase.Expect( ConstantsDemoConstants.GEN_SET.size == 2, "GEN_SET.size() == 2");
-        TestBase.Expect( ConstantsDemoConstants.GEN_SET.contains(235), "GEN_SET.contains(235)");  // added twice, but this is a set
-        TestBase.Expect( ConstantsDemoConstants.GEN_SET.contains(53235), "GEN_SET.contains(53235)");
-    }
-
-}
-
-
diff --git a/lib/haxe/test/src/Main.hx b/lib/haxe/test/src/Main.hx
index 5976bb0..5e69839 100644
--- a/lib/haxe/test/src/Main.hx
+++ b/lib/haxe/test/src/Main.hx
@@ -20,83 +20,92 @@
 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 org.apache.thrift.protocol.*;
+import org.apache.thrift.server.*;
+import org.apache.thrift.transport.*;
+import tests.ConstantsTest;
+import tests.MultiplexTest;
+import tests.StreamTest;
+import thrift.test.*;
 
-import thrift.test.*;  // generated code
-
-
-enum WhatTests {
-    Normal;
-    Multiplex;
-    Constants;
+enum WhatTests
+{
+	Normal;
+	Multiplex;
+	Constants;
 }
 
 class Main
 {
-    static private var tests : WhatTests = Normal;
-    static private var server : Bool = false;
+	static private var what : WhatTests = Normal;
+	static private var server : Bool = false;
 
-    static private inline var CMDLINEHELP : String
-        = "\nHaxeTests  [client|server]  [multiplex]\n"
-        + "  client|server  ... determines run mode for some tests, default is client\n"
-        + "  multiplex ........ run multiplex test server or client\n";
+	static private inline var CMDLINEHELP : String
+		= "\nHaxeTests  [client|server]  [multiplex]\n"
+		  + "  client|server  ... determines run mode for some tests, default is client\n"
+		  + "  multiplex ........ run multiplex test server or client\n"
+		  + "  constants ........ run constants and conformity tests\n"
+		  ;
 
-    static private function ParseArgs() {
-        #if sys
+	static private function ParseArgs()
+	{
+		#if sys
 
-        var args = Sys.args();
-        if ( args != null) {
-            for ( arg in args) {
-                switch(arg.toLowerCase()) {
-                    case "client":
-                        server = false;
-                    case "server" :
-                        server = true;
-                    case "multiplex" :
-                        tests = Multiplex;
-                    case "constants" :
-                        tests = Constants;
-                    default:
-                throw 'Invalid argument "$arg"\n'+CMDLINEHELP;
-                }
-            }
-        }
+		var args = Sys.args();
+		if ( args != null)
+		{
+			for ( arg in args)
+			{
+				switch (arg.toLowerCase())
+				{
+					case "client":
+						server = false;
+					case "server" :
+						server = true;
+					case "multiplex" :
+						what = Multiplex;
+					case "constants" :
+						what = Constants;
+					default:
+						throw 'Invalid argument "$arg"\n'+CMDLINEHELP;
+				}
+			}
+		}
 
-        #end
-    }
+		#end
+	}
 
-    static public function main()
-    {
-        try
-        {
-            ParseArgs();
+	static public function main()
+	{
+		try
+		{
+			ParseArgs();
 
-            switch( tests) {
-                case Normal:
-                    #if sys
-                    StreamTest.Run(server);
-                    #end
-                case Multiplex:
-                    #if ! (flash || html5 || js)
-                    MultiplexTest.Run(server);
-                    #end
-                case Constants:
-                    ConstantsTest.Run(server);
-                default:
-                    throw "Unhandled test mode $tests";
-            }
+			switch ( what)
+			{
+				case Normal:
+					#if sys
+					tests.StreamTest.Run(server);
+					#end
+				case Multiplex:
+					#if ! (flash || html5 || js)
+					tests.MultiplexTest.Run(server);
+					#end
+				case Constants:
+					tests.ConstantsTest.Run(server);
+				default:
+					throw 'Unhandled test mode $what';
+			}
 
-            trace("All tests completed.");
-        }
-        catch( e: Dynamic)
-        {
-            trace('$e');
-            #if sys
-            Sys.exit(1);  // indicate error
-            #end
-        }
-    }
+			trace("All tests completed.");
+		}
+		catch ( e: Dynamic)
+		{
+			trace('$e');
+			#if sys
+			Sys.exit(1);  // indicate error
+			#end
+		}
+	}
 }
\ No newline at end of file
diff --git a/lib/haxe/test/src/tests/ConstantsTest.hx b/lib/haxe/test/src/tests/ConstantsTest.hx
new file mode 100644
index 0000000..11b266c
--- /dev/null
+++ b/lib/haxe/test/src/tests/ConstantsTest.hx
@@ -0,0 +1,150 @@
+/*
+ * 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 tests;
+
+import haxe.Int64;
+import haxe.io.BytesBuffer;
+import tests.TestBase;
+
+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 constantsDemo.*;  // generated code
+
+
+class ConstantsTest extends tests.TestBase {
+
+    public static function Run(server : Bool) : Void
+    {
+		TestConstants();		
+    	TestProtocolConformity();
+    }
+
+
+	private static function TestConstants() : Void
+	{
+        tests.TestBase.Expect( ConstantsDemoConstants.myInt == 3, "myInt = 3");
+        tests.TestBase.Expect( ConstantsDemoConstants.hex_const == 0x0001F, "hex_const = 31");
+        tests.TestBase.Expect( ConstantsDemoConstants.negative_hex_constant == -0x0001F, "negative_hex_constant = -31");
+        tests.TestBase.Expect( ConstantsDemoConstants.GEN_ME == -3523553, "GEN_ME = -3523553");
+        tests.TestBase.Expect( ConstantsDemoConstants.GEn_DUB == 325.532, "GEn_DUB = 325.532");
+        tests.TestBase.Expect( ConstantsDemoConstants.GEn_DU == 85.2355, "GEn_DU = 85.2355");
+        tests.TestBase.Expect( ConstantsDemoConstants.GEN_STRING == "asldkjasfd", "GEN_STRING = \"asldkjasfd\"");
+        tests.TestBase.Expect( ConstantsDemoConstants.e10 == 1e+10, "e10 = 1e+10");
+        tests.TestBase.Expect( ConstantsDemoConstants.e11 == -1e+10, "e11 = -1e+10");
+        tests.TestBase.Expect( ConstantsDemoConstants.GEN_UUID == "00000000-4444-CCCC-ffff-0123456789ab", "GEN_UUID = \"00000000-4444-CCCC-ffff-0123456789ab\"");
+
+        tests.TestBase.Expect( ConstantsDemoConstants.GEN_MAP.get(35532) == 233, "GEN_MAP.get(35532) == 233");
+        tests.TestBase.Expect( ConstantsDemoConstants.GEN_MAP.get(43523) == 853, "GEN_MAP.get(43523) == 853");
+        
+        tests.TestBase.Expect( ConstantsDemoConstants.GEN_LIST.length == 3, "GEN_LIST.size() == 3");
+        tests.TestBase.Expect( ConstantsDemoConstants.GEN_LIST.join("/") == "235235/23598352/3253523", "GEN_LIST elements");
+
+        tests.TestBase.Expect( ConstantsDemoConstants.GEN_MAPMAP.get(235).get(532) == 53255, "GEN_MAPMAP.get(235).get(532) == 53255");
+        tests.TestBase.Expect( ConstantsDemoConstants.GEN_MAPMAP.get(235).get(235) == 235, "GEN_MAPMAP.get(235).get(235) == 235");
+
+        tests.TestBase.Expect( ConstantsDemoConstants.GEN_MAP2.get("hello") == 233, "GEN_MAP2.get(\"hello\") == 233");
+        tests.TestBase.Expect( ConstantsDemoConstants.GEN_MAP2.get("lkj98d") == 853, "GEN_MAP2.get(\"lkj98d\") == 853");
+        tests.TestBase.Expect( ConstantsDemoConstants.GEN_MAP2.get('lkjsdf') == 98325, "GEN_MAP2.get('lkjsdf') == 98325");
+        
+        tests.TestBase.Expect( ConstantsDemoConstants.GEN_THING.hello == 325, "GEN_THING.hello == 325");
+        tests.TestBase.Expect( ConstantsDemoConstants.GEN_THING.goodbye == 325352, "GEN_THING.goodbye == 325352");
+
+        tests.TestBase.Expect( ConstantsDemoConstants.GEN_WHAT.get(35).hello == 325, "GEN_WHAT.get(35).hello == 325");
+        tests.TestBase.Expect( ConstantsDemoConstants.GEN_WHAT.get(35).goodbye == 325352, "GEN_WHAT.get(35).goodbye == 325352");
+
+        tests.TestBase.Expect( ConstantsDemoConstants.GEN_SET.size == 2, "GEN_SET.size() == 2");
+        tests.TestBase.Expect( ConstantsDemoConstants.GEN_SET.contains(235), "GEN_SET.contains(235)");  // added twice, but this is a set
+        tests.TestBase.Expect( ConstantsDemoConstants.GEN_SET.contains(53235), "GEN_SET.contains(53235)");
+    }
+
+	private static function TestProtocolConformity() : Void
+	{
+		for( factory in [new TBinaryProtocolFactory(), new TCompactProtocolFactory(), new TJSONProtocolFactory()])
+		{
+			DeserializeGuidData(factory);
+		}
+    }
+
+	private static function DeserializeGuidData(factory : TProtocolFactory) : Void
+	{
+		var data = new BytesBuffer();
+		var sCase = Type.getClassName(Type.getClass(factory)).split('.').pop();
+		switch(sCase)
+		{
+			case "TJSONProtocolFactory":
+				data.addString('"00112233-4455-6677-8899-aabbccddeeff"');
+
+			case "TCompactProtocolFactory":
+				data.addByte(0x00);
+				data.addByte(0x11);
+				data.addByte(0x22);
+				data.addByte(0x33);
+				data.addByte(0x44);
+				data.addByte(0x55);
+				data.addByte(0x66);
+				data.addByte(0x77);
+				data.addByte(0x88);
+				data.addByte(0x99);
+				data.addByte(0xaa);
+				data.addByte(0xbb);
+				data.addByte(0xcc);
+				data.addByte(0xdd);
+				data.addByte(0xee);
+				data.addByte(0xff);
+
+			case "TBinaryProtocolFactory":
+				data.addByte(0x00);
+				data.addByte(0x11);
+				data.addByte(0x22);
+				data.addByte(0x33);
+				data.addByte(0x44);
+				data.addByte(0x55);
+				data.addByte(0x66);
+				data.addByte(0x77);
+				data.addByte(0x88);
+				data.addByte(0x99);
+				data.addByte(0xaa);
+				data.addByte(0xbb);
+				data.addByte(0xcc);
+				data.addByte(0xdd);
+				data.addByte(0xee);
+				data.addByte(0xff);
+
+			default:
+				tests.TestBase.Expect( false, 'Unhandled ${sCase}');
+		}
+
+		var stream = new TMemoryStream(data.getBytes());
+		stream.Position = 0;
+		
+		var config = new TConfiguration();
+		var transport = new TStreamTransport(stream, stream, config);
+		var protocol = factory.getProtocol(transport);
+		
+		var sUuid = protocol.readUuid();	
+		tests.TestBase.Expect( sUuid == "00112233-4455-6677-8899-aabbccddeeff", 'DeserializeGuidData(${sCase}): ${sUuid}');
+	}
+}
+
+
diff --git a/lib/haxe/test/src/MultiplexTest.hx b/lib/haxe/test/src/tests/MultiplexTest.hx
similarity index 91%
rename from lib/haxe/test/src/MultiplexTest.hx
rename to lib/haxe/test/src/tests/MultiplexTest.hx
index a17bf15..8676082 100644
--- a/lib/haxe/test/src/MultiplexTest.hx
+++ b/lib/haxe/test/src/tests/MultiplexTest.hx
@@ -17,7 +17,8 @@
  * under the License.
  */
 
-package;
+package tests;
+import tests.TestBase;
 
 #if ! (flash || html5 || js)
 
@@ -86,7 +87,7 @@
 
 
 
-class MultiplexTest extends TestBase {
+class MultiplexTest extends tests.TestBase {
 
     private inline static var NAME_BENCHMARKSERVICE : String = "BenchmarkService";
     private inline static var NAME_AGGR             : String  = "Aggr";
@@ -128,11 +129,11 @@
        }
         catch( e : TApplicationException)
         {
-            TestBase.Expect(false,'${e.errorID} ${e.errorMsg}');
+            tests.TestBase.Expect(false,'${e.errorID} ${e.errorMsg}');
         }
         catch( e : TException)
         {
-            TestBase.Expect(false,'$e');
+            tests.TestBase.Expect(false,'$e');
         }
     }
 
@@ -165,7 +166,7 @@
             trace('calling aggr ...');
             var i = 1;
             var values = aggr.getValues();
-            TestBase.Expect(values != null,'aggr.getValues() == null');
+            tests.TestBase.Expect(values != null,'aggr.getValues() == null');
             for( k in values)
             {
                 trace('fib($i) = $k');
@@ -178,11 +179,11 @@
         }
         catch( e : TApplicationException)
         {
-            TestBase.Expect(false,'${e.errorID} ${e.errorMsg}');
+            tests.TestBase.Expect(false,'${e.errorID} ${e.errorMsg}');
         }
         catch( e : TException)
         {
-            TestBase.Expect(false,'$e');
+            tests.TestBase.Expect(false,'$e');
         }
     }
 
@@ -212,11 +213,11 @@
         }
         catch( e : TApplicationException)
         {
-            TestBase.Expect(false,'${e.errorID} ${e.errorMsg}');
+            tests.TestBase.Expect(false,'${e.errorID} ${e.errorMsg}');
         }
         catch( e : TException)
         {
-            TestBase.Expect(false,'$e');
+            tests.TestBase.Expect(false,'$e');
         }
     }
 
diff --git a/lib/haxe/test/src/StreamTest.hx b/lib/haxe/test/src/tests/StreamTest.hx
similarity index 84%
rename from lib/haxe/test/src/StreamTest.hx
rename to lib/haxe/test/src/tests/StreamTest.hx
index 3e70ada..97af6f3 100644
--- a/lib/haxe/test/src/StreamTest.hx
+++ b/lib/haxe/test/src/tests/StreamTest.hx
@@ -17,7 +17,8 @@
  * under the License.
  */
 
-package;
+package tests;
+import tests.TestBase;
 #if sys
 
 import haxe.Int64;
@@ -32,7 +33,7 @@
 import thrift.test.*;  // generated code
 
 
-class StreamTest extends TestBase {
+class StreamTest extends tests.TestBase {
 
 
     private inline static var tmpfile : String = "data.tmp";
@@ -82,10 +83,10 @@
             var read = ReadData();
             FileSystem.deleteFile(tmpfile);
 
-            TestBase.Expect( read.string_thing == written.string_thing, "string data");
-            TestBase.Expect( read.byte_thing == written.byte_thing, "byte data");
-            TestBase.Expect( read.i32_thing == written.i32_thing, "i32 data");
-            TestBase.Expect( Int64.compare( read.i64_thing, written.i64_thing) == 0, "i64 data");
+            tests.TestBase.Expect( read.string_thing == written.string_thing, "string data");
+            tests.TestBase.Expect( read.byte_thing == written.byte_thing, "byte data");
+            tests.TestBase.Expect( read.i32_thing == written.i32_thing, "i32 data");
+            tests.TestBase.Expect( Int64.compare( read.i64_thing, written.i64_thing) == 0, "i64 data");
 
         } catch(e:Dynamic) {
             FileSystem.deleteFile(tmpfile);
diff --git a/lib/haxe/test/src/TestBase.hx b/lib/haxe/test/src/tests/TestBase.hx
similarity index 98%
rename from lib/haxe/test/src/TestBase.hx
rename to lib/haxe/test/src/tests/TestBase.hx
index 865a801..7545a65 100644
--- a/lib/haxe/test/src/TestBase.hx
+++ b/lib/haxe/test/src/tests/TestBase.hx
@@ -17,7 +17,7 @@
  * under the License.
  */
 
-package;
+package tests;
 
 import org.apache.thrift.*;
 import org.apache.thrift.protocol.*;