diff --git a/lib/delphi/src/Thrift.Serializer.pas b/lib/delphi/src/Thrift.Serializer.pas
index 8ee8a3540dc..c354a37dacc 100644
--- a/lib/delphi/src/Thrift.Serializer.pas
+++ b/lib/delphi/src/Thrift.Serializer.pas
@@ -66,7 +66,7 @@ TDeserializer = class
public
constructor Create( const aProtFact : IProtocolFactory = nil; // defaults to TBinaryProtocol
const aTransFact : ITransportFactory = nil;
- const aConfig : IThriftConfiguration = nil);
+ const aConfig : IThriftConfiguration = nil);
// DTOR
destructor Destroy; override;
@@ -74,6 +74,11 @@ TDeserializer = class
// Deserialize the Thrift object data.
procedure Deserialize( const input : TBytes; const target : IBase); overload;
procedure Deserialize( const input : TStream; const target : IBase); overload;
+
+ // helper
+ property Protocol : IProtocol read FProtocol;
+ property Transport : ITransport read FTransport;
+ property Stream : TThriftMemoryStream read FStream;
end;
@@ -164,14 +169,14 @@ procedure TSerializer.Serialize( const input : IBase; const aStm : TStream);
constructor TDeserializer.Create( const aProtFact : IProtocolFactory;
const aTransFact : ITransportFactory;
- const aConfig : IThriftConfiguration);
+ const aConfig : IThriftConfiguration);
var adapter : IThriftStream;
protfact : IProtocolFactory;
begin
inherited Create;
- FStream := TThriftMemoryStream.Create;
- adapter := TThriftStreamAdapterDelphi.Create( FStream, FALSE);
+ FStream := TThriftMemoryStream.Create;
+ adapter := TThriftStreamAdapterDelphi.Create( FStream, FALSE);
FTransport := TStreamTransportImpl.Create( adapter, nil, aConfig);
if aTransfact <> nil then FTransport := aTransfact.GetTransport( FTransport);
@@ -205,8 +210,11 @@ procedure TDeserializer.Deserialize( const input : TBytes; const target : IBase)
try
iBytes := Length(input);
FStream.Size := iBytes;
- if iBytes > 0
- then Move( input[0], FStream.Memory^, iBytes);
+ if iBytes > 0 then begin
+ Move( input[0], FStream.Memory^, iBytes);
+ Transport.ResetMessageSizeAndConsumedBytes(); // size has changed
+ Transport.UpdateKnownMessageSize(iBytes);
+ end;
target.Read( FProtocol);
finally
@@ -221,9 +229,15 @@ procedure TDeserializer.Deserialize( const input : TStream; const target : IBase
var before : Int64;
begin
try
- before := FStream.Position;
- FStream.CopyFrom( input, COPY_ENTIRE_STREAM);
- FStream.Position := before;
+ if Assigned(input) then begin
+ before := FStream.Position;
+ ASSERT( before = 0);
+ FStream.CopyFrom( input, COPY_ENTIRE_STREAM);
+ FStream.Position := before;
+ Transport.ResetMessageSizeAndConsumedBytes(); // size has changed
+ Transport.UpdateKnownMessageSize(FStream.Size);
+ end;
+
target.Read( FProtocol);
finally
FStream.Size := 0; // free any allocated memory
diff --git a/lib/delphi/test/serializer/TestSerializer.Tests.pas b/lib/delphi/test/serializer/TestSerializer.Tests.pas
index 466fb269efc..7f5b829ec51 100644
--- a/lib/delphi/test/serializer/TestSerializer.Tests.pas
+++ b/lib/delphi/test/serializer/TestSerializer.Tests.pas
@@ -49,7 +49,7 @@ interface
type
TFactoryPair = record
- prot : IProtocolFactory;
+ proto : IProtocolFactory;
trans : ITransportFactory;
end;
@@ -72,8 +72,9 @@ TTestSerializer = class //extends TestCase {
class procedure Deserialize( const input : TBytes; const target : IBase; const factory : TFactoryPair); overload;
class procedure Deserialize( const input : TStream; const target : IBase; const factory : TFactoryPair); overload;
- class procedure ValidateReadToEnd( const input : TBytes; const serial : TDeserializer); overload;
- class procedure ValidateReadToEnd( const input : TStream; const serial : TDeserializer); overload;
+ class procedure Deserialize( const input : TBytes; out target : TGuid; const factory : TFactoryPair); overload;
+
+ class procedure ValidateReadToEnd( const serial : TDeserializer); overload;
class function LengthOf( const bytes : TBytes) : Integer; overload; inline;
class function LengthOf( const bytes : IThriftBytes) : Integer; overload; inline;
@@ -90,6 +91,9 @@ TTestSerializer = class //extends TestCase {
procedure Test_ExceptionStruct( const method : TMethod; const factory : TFactoryPair; const stream : TFileStream);
procedure Test_SimpleException( const method : TMethod; const factory : TFactoryPair; const stream : TFileStream);
+ procedure Test_ProtocolConformity( const factory : TFactoryPair; const stream : TFileStream);
+ procedure Test_UuidDeserialization( const factory : TFactoryPair; const stream : TFileStream);
+
public
constructor Create;
destructor Destroy; override;
@@ -143,7 +147,7 @@ destructor TTestSerializer.Destroy;
procedure TTestSerializer.AddFactoryCombination( const aProto : IProtocolFactory; const aTrans : ITransportFactory);
var rec : TFactoryPair;
begin
- rec.prot := aProto;
+ rec.proto := aProto;
rec.trans := aTrans;
FProtocols.Add( rec);
end;
@@ -177,6 +181,53 @@ class function TTestSerializer.DataPtrOf( const bytes : IThriftBytes) : Pointer;
end;
+procedure TTestSerializer.Test_ProtocolConformity( const factory : TFactoryPair; const stream : TFileStream);
+begin
+ Test_UuidDeserialization( factory, stream);
+ // add more tests here
+end;
+
+
+procedure TTestSerializer.Test_UuidDeserialization( const factory : TFactoryPair; const stream : TFileStream);
+
+ function CreateGuidBytes : TBytes;
+ var obj : TObject;
+ i : Integer;
+ begin
+ obj := factory.proto as TObject;
+
+ if obj is TJSONProtocolImpl.TFactory then begin
+ result := TEncoding.UTF8.GetBytes('"00112233-4455-6677-8899-aabbccddeeff"');
+ Exit;
+ end;
+
+ if (obj is TBinaryProtocolImpl.TFactory)
+ or (obj is TCompactProtocolImpl.TFactory)
+ then begin
+ SetLength(result,16);
+ for i := 0 to Length(result)-1 do result[i] := (i * $10) + i;
+ Exit;
+ end;
+
+ raise Exception.Create('Unhandled case');
+ end;
+
+
+var tested, correct : TGuid;
+ bytes : TBytes;
+begin
+ // write
+ bytes := CreateGuidBytes();
+
+ // init + read
+ Deserialize( bytes, tested, factory);
+
+ // check
+ correct := TGuid.Create('{00112233-4455-6677-8899-aabbccddeeff}');
+ ASSERT( tested = correct);
+end;
+
+
procedure TTestSerializer.Test_OneOfEach( const method : TMethod; const factory : TFactoryPair; const stream : TFileStream);
var tested, correct : IOneOfEach;
bytes : TBytes;
@@ -385,6 +436,11 @@ procedure TTestSerializer.Test_Serializer_Deserializer;
for factory in FProtocols do begin
Writeln('- '+UserFriendlyName(factory));
+ // protocol conformity tests
+ if (method = TMethod.mt_Bytes) and (factory.trans = nil)
+ then Test_ProtocolConformity( factory, stream);
+
+ // normal objects
Test_OneOfEach( method, factory, stream);
Test_CompactStruct( method, factory, stream);
Test_ExceptionStruct( method, factory, stream);
@@ -402,7 +458,7 @@ procedure TTestSerializer.Test_Serializer_Deserializer;
class function TTestSerializer.UserFriendlyName( const factory : TFactoryPair) : string;
begin
- result := Copy( (factory.prot as TObject).ClassName, 2, MAXINT);
+ result := Copy( (factory.proto as TObject).ClassName, 2, MAXINT);
if factory.trans <> nil
then result := Copy( (factory.trans as TObject).ClassName, 2, MAXINT) +' '+ result;
@@ -472,7 +528,7 @@ class function TTestSerializer.Serialize(const input : IBase; const factory : TF
config := TThriftConfigurationImpl.Create;
//config.MaxMessageSize := 0; // we don't read anything here
- serial := TSerializer.Create( factory.prot, factory.trans, config);
+ serial := TSerializer.Create( factory.proto, factory.trans, config);
try
result := serial.Serialize( input);
finally
@@ -488,7 +544,7 @@ class procedure TTestSerializer.Serialize(const input : IBase; const factory : T
config := TThriftConfigurationImpl.Create;
//config.MaxMessageSize := 0; // we don't read anything here
- serial := TSerializer.Create( factory.prot, factory.trans, config);
+ serial := TSerializer.Create( factory.proto, factory.trans, config);
try
serial.Serialize( input, aStream);
finally
@@ -504,10 +560,10 @@ class procedure TTestSerializer.Deserialize( const input : TBytes; const target
config := TThriftConfigurationImpl.Create;
config.MaxMessageSize := Length(input);
- serial := TDeserializer.Create( factory.prot, factory.trans, config);
+ serial := TDeserializer.Create( factory.proto, factory.trans, config);
try
serial.Deserialize( input, target);
- ValidateReadToEnd( input, serial);
+ ValidateReadToEnd( serial);
finally
serial.Free;
end;
@@ -521,44 +577,49 @@ class procedure TTestSerializer.Deserialize( const input : TStream; const target
config := TThriftConfigurationImpl.Create;
config.MaxMessageSize := input.Size;
- serial := TDeserializer.Create( factory.prot, factory.trans, config);
+ serial := TDeserializer.Create( factory.proto, factory.trans, config);
try
serial.Deserialize( input, target);
- ValidateReadToEnd( input, serial);
+ ValidateReadToEnd( serial);
finally
serial.Free;
end;
end;
-class procedure TTestSerializer.ValidateReadToEnd( const input : TBytes; const serial : TDeserializer);
-// we should not have any more byte to read
-var dummy : IBase;
+class procedure TTestSerializer.Deserialize( const input : TBytes; out target : TGuid; const factory : TFactoryPair);
+var serial : TDeserializer;
+ config : IThriftConfiguration;
begin
+ config := TThriftConfigurationImpl.Create;
+ config.MaxMessageSize := Length(input);
+
+ serial := TDeserializer.Create( factory.proto, factory.trans, config);
try
- dummy := TOneOfEachImpl.Create;
- serial.Deserialize( input, dummy);
- raise EInOutError.Create('Expected exception not thrown?');
- except
- on e:TTransportExceptionEndOfFile do {expected};
- on e:Exception do raise; // unexpected
+ serial.Stream.Write(input[0], Length(input));
+ serial.Stream.Position := 0;
+ serial.Transport.ResetMessageSizeAndConsumedBytes(); // size has changed
+
+ target := serial.Protocol.ReadUuid;
+ finally
+ serial.Free;
end;
end;
-class procedure TTestSerializer.ValidateReadToEnd( const input : TStream; const serial : TDeserializer);
+class procedure TTestSerializer.ValidateReadToEnd( const serial : TDeserializer);
// we should not have any more byte to read
var dummy : IBase;
begin
try
- input.Position := 0;
dummy := TOneOfEachImpl.Create;
- serial.Deserialize( input, dummy);
+ serial.Deserialize( nil, dummy);
raise EInOutError.Create('Expected exception not thrown?');
except
- on e:TTransportExceptionEndOfFile do {expected};
+ on e:TTransportException do {expected};
on e:Exception do raise; // unexpected
end;
end;
+
end.
diff --git a/lib/haxe/src/org/apache/thrift/TConfiguration.hx b/lib/haxe/src/org/apache/thrift/TConfiguration.hx
index 47973f2c2c0..3bc5a864f8c 100644
--- a/lib/haxe/src/org/apache/thrift/TConfiguration.hx
+++ b/lib/haxe/src/org/apache/thrift/TConfiguration.hx
@@ -25,9 +25,9 @@ class TConfiguration
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/src/org/apache/thrift/transport/TMemoryStream.hx b/lib/haxe/src/org/apache/thrift/transport/TMemoryStream.hx
new file mode 100644
index 00000000000..49b494e64d2
--- /dev/null
+++ b/lib/haxe/src/org/apache/thrift/transport/TMemoryStream.hx
@@ -0,0 +1,88 @@
+/*
+ * 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 org.apache.thrift.transport;
+
+import haxe.io.Bytes;
+import haxe.io.BytesBuffer;
+import haxe.io.Output;
+
+class TMemoryStream implements TStream {
+
+ private var Data : Bytes;
+ public var Position(default,default) : Int;
+
+ public function new( data : Bytes = null) {
+ var target = new BytesBuffer();
+ if ( data != null) {
+ for ( i in 0...data.length) {
+ target.addByte( data.get(i));
+ ++Position;
+ }
+ }
+ Data = target.getBytes();
+ }
+
+ private function IsEof() : Bool {
+ return (0 > Position) || (Position >= Data.length);
+ }
+
+ public function Close() : Void {
+ var target = new BytesBuffer();
+ Data = target.getBytes();
+ Position = 0;
+ }
+
+ public function Peek() : Bool {
+ return (! IsEof());
+ }
+
+ // read count bytes into buf starting at offset
+ public function Read( buf : Bytes, offset : Int, count : Int) : Int {
+ var numRead = 0;
+
+ for ( i in 0...count) {
+ if ( IsEof())
+ break;
+
+ buf.set( offset + i, Data.get( Position++));
+ ++numRead;
+ }
+
+ return numRead;
+ }
+
+ // write count bytes from buf starting at offset
+ public function Write( buf : Bytes, offset : Int, count : Int) : Void {
+ var numBytes = buf.length - offset;
+ if ( numBytes > count) {
+ numBytes = count;
+ }
+
+ for ( i in 0...numBytes) {
+ Data.set( Position + i, buf.get( offset + i));
+ }
+ }
+
+ public function Flush() : Void {
+ // nothing to do
+ }
+
+}
+
diff --git a/lib/haxe/test/HaxeTests.hxproj b/lib/haxe/test/HaxeTests.hxproj
index 839917b4757..fbb9c8e5ef0 100644
--- a/lib/haxe/test/HaxeTests.hxproj
+++ b/lib/haxe/test/HaxeTests.hxproj
@@ -63,7 +63,7 @@ thrift -r -gen haxe ../../../lib/rb/benchmark/Benchmark.thrift
-
+
diff --git a/lib/haxe/test/src/ConstantsTest.hx b/lib/haxe/test/src/ConstantsTest.hx
deleted file mode 100644
index d0041e49f43..00000000000
--- 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 5976bb0871a..5e698396fd6 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.meta_data.*;
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
-
+import org.apache.thrift.transport.*;
+import tests.ConstantsTest;
+import tests.MultiplexTest;
+import tests.StreamTest;
+import thrift.test.*;
-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 00000000000..11b266c0cb8
--- /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 92%
rename from lib/haxe/test/src/MultiplexTest.hx
rename to lib/haxe/test/src/tests/MultiplexTest.hx
index a17bf1589ba..86760823801 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 AggrServiceHandler implements Aggr_service
-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 @@ class MultiplexTest extends TestBase {
}
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 @@ class MultiplexTest extends TestBase {
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 @@ class MultiplexTest extends TestBase {
}
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 @@ class MultiplexTest extends TestBase {
}
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 85%
rename from lib/haxe/test/src/StreamTest.hx
rename to lib/haxe/test/src/tests/StreamTest.hx
index 3e70adaf5bd..97af6f3add8 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 org.apache.thrift.meta_data.*;
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 @@ class StreamTest extends TestBase {
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 865a801a970..7545a65e025 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.*;
diff --git a/lib/netstd/Tests/Thrift.IntegrationTests/Protocols/ProtocolConformityTests.cs b/lib/netstd/Tests/Thrift.IntegrationTests/Protocols/ProtocolConformityTests.cs
new file mode 100644
index 00000000000..8c5988f2be7
--- /dev/null
+++ b/lib/netstd/Tests/Thrift.IntegrationTests/Protocols/ProtocolConformityTests.cs
@@ -0,0 +1,90 @@
+// 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.
+
+using System;
+using System.IO;
+using System.Text;
+using System.Threading;
+using System.Threading.Tasks;
+using KellermanSoftware.CompareNetObjects;
+using Microsoft.VisualStudio.TestTools.UnitTesting;
+using Thrift.Protocol;
+using Thrift.Protocol.Entities;
+using Thrift.Transport;
+using Thrift.Transport.Client;
+
+namespace Thrift.IntegrationTests.Protocols
+{
+ [TestClass]
+ public class ProtocolConformityTests : TestBase
+ {
+ [DataTestMethod]
+ [DataRow(typeof(TBinaryProtocol))]
+ [DataRow(typeof(TCompactProtocol))]
+ [DataRow(typeof(TJsonProtocol))]
+ public async Task ReadUuidFromStream(Type protocolType)
+ {
+ var expected = new Guid("{00112233-4455-6677-8899-aabbccddeeff}");
+
+ try
+ {
+ var tuple = GetProtocolInstance(protocolType);
+ using var stream = tuple.Stream;
+
+ await GenerateGuidTestData(stream, protocolType, default);
+ stream.Seek(0, SeekOrigin.Begin);
+ tuple.Transport.ResetMessageSizeAndConsumedBytes(); // length has changed
+
+ var actual = await tuple.Protocol.ReadUuidAsync(default);
+
+ var result = _compareLogic.Compare(expected, actual);
+ Assert.IsTrue(result.AreEqual, result.DifferencesString);
+ }
+ catch (Exception e)
+ {
+ throw new Exception($"Exception during testing of protocol: {protocolType.FullName}", e);
+ }
+ }
+
+ private static async Task GenerateGuidTestData(Stream stream, Type protocolType, CancellationToken cancel)
+ {
+ stream.Seek(0, SeekOrigin.Begin);
+
+ if(protocolType == typeof(TJsonProtocol))
+ {
+ await stream.WriteAsync(Encoding.UTF8.GetBytes("\"00112233-4455-6677-8899-aabbccddeeff\""), cancel);
+ return;
+ }
+
+ if (protocolType == typeof(TBinaryProtocol))
+ {
+ var data = new byte[16] { 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff };
+ await stream.WriteAsync(data, cancel);
+ return;
+ }
+
+ if (protocolType == typeof(TCompactProtocol))
+ {
+ var data = new byte[16] { 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff };
+ await stream.WriteAsync(data, cancel);
+ return;
+ }
+
+ throw new Exception($"Unhandled protocol: {protocolType.FullName}");
+ }
+ }
+}
diff --git a/lib/netstd/Tests/Thrift.IntegrationTests/Protocols/ProtocolsOperationsTests.cs b/lib/netstd/Tests/Thrift.IntegrationTests/Protocols/ProtocolsOperationsTests.cs
index f9f3117a6fc..844bd10d200 100644
--- a/lib/netstd/Tests/Thrift.IntegrationTests/Protocols/ProtocolsOperationsTests.cs
+++ b/lib/netstd/Tests/Thrift.IntegrationTests/Protocols/ProtocolsOperationsTests.cs
@@ -31,11 +31,8 @@
namespace Thrift.IntegrationTests.Protocols
{
[TestClass]
- public class ProtocolsOperationsTests
+ public class ProtocolsOperationsTests : TestBase
{
- private readonly CompareLogic _compareLogic = new();
- private static readonly TConfiguration Configuration = new();
-
[DataTestMethod]
[DataRow(typeof(TBinaryProtocol), TMessageType.Call)]
[DataRow(typeof(TBinaryProtocol), TMessageType.Exception)]
@@ -99,7 +96,7 @@ public async Task WriteReadStruct_Test(Type protocolType)
await protocol.WriteStructEndAsync(default);
await tuple.Transport.FlushAsync(default);
- stream?.Seek(0, SeekOrigin.Begin);
+ stream.Seek(0, SeekOrigin.Begin);
var actual = await protocol.ReadStructBeginAsync(default);
await protocol.ReadStructEndAsync(default);
@@ -135,7 +132,7 @@ public async Task WriteReadField_Test(Type protocolType)
await protocol.WriteFieldEndAsync(default);
await tuple.Transport.FlushAsync(default);
- stream?.Seek(0, SeekOrigin.Begin);
+ stream.Seek(0, SeekOrigin.Begin);
var actual = await protocol.ReadFieldBeginAsync(default);
await protocol.ReadFieldEndAsync(default);
@@ -169,7 +166,7 @@ public async Task WriteReadMap_Test(Type protocolType)
await protocol.WriteMapEndAsync(default);
await tuple.Transport.FlushAsync(default);
- stream?.Seek(0, SeekOrigin.Begin);
+ stream.Seek(0, SeekOrigin.Begin);
var actual = await protocol.ReadMapBeginAsync(default);
await protocol.ReadMapEndAsync(default);
@@ -204,7 +201,7 @@ public async Task WriteReadList_Test(Type protocolType)
await protocol.WriteListEndAsync(default);
await tuple.Transport.FlushAsync(default);
- stream?.Seek(0, SeekOrigin.Begin);
+ stream.Seek(0, SeekOrigin.Begin);
var actual = await protocol.ReadListBeginAsync(default);
await protocol.ReadListEndAsync(default);
@@ -238,7 +235,7 @@ public async Task WriteReadSet_Test(Type protocolType)
await protocol.WriteSetEndAsync(default);
await tuple.Transport.FlushAsync(default);
- stream?.Seek(0, SeekOrigin.Begin);
+ stream.Seek(0, SeekOrigin.Begin);
var actual = await protocol.ReadSetBeginAsync(default);
await protocol.ReadSetEndAsync(default);
@@ -271,7 +268,7 @@ public async Task WriteReadBool_Test(Type protocolType)
await protocol.WriteBoolAsync(expected, default);
await tuple.Transport.FlushAsync(default);
- stream?.Seek(0, SeekOrigin.Begin);
+ stream.Seek(0, SeekOrigin.Begin);
var actual = await protocol.ReadBoolAsync(default);
@@ -303,7 +300,7 @@ public async Task WriteReadByte_Test(Type protocolType)
await protocol.WriteByteAsync(expected, default);
await tuple.Transport.FlushAsync(default);
- stream?.Seek(0, SeekOrigin.Begin);
+ stream.Seek(0, SeekOrigin.Begin);
var actual = await protocol.ReadByteAsync(default);
@@ -335,7 +332,7 @@ public async Task WriteReadI16_Test(Type protocolType)
await protocol.WriteI16Async(expected, default);
await tuple.Transport.FlushAsync(default);
- stream?.Seek(0, SeekOrigin.Begin);
+ stream.Seek(0, SeekOrigin.Begin);
var actual = await protocol.ReadI16Async(default);
@@ -367,7 +364,7 @@ public async Task WriteReadI32_Test(Type protocolType)
await protocol.WriteI32Async(expected, default);
await tuple.Transport.FlushAsync(default);
- stream?.Seek(0, SeekOrigin.Begin);
+ stream.Seek(0, SeekOrigin.Begin);
var actual = await protocol.ReadI32Async(default);
@@ -399,7 +396,7 @@ public async Task WriteReadI64_Test(Type protocolType)
await protocol.WriteI64Async(expected, default);
await tuple.Transport.FlushAsync(default);
- stream?.Seek(0, SeekOrigin.Begin);
+ stream.Seek(0, SeekOrigin.Begin);
var actual = await protocol.ReadI64Async(default);
@@ -431,7 +428,7 @@ public async Task WriteReadDouble_Test(Type protocolType)
await protocol.WriteDoubleAsync(expected, default);
await tuple.Transport.FlushAsync(default);
- stream?.Seek(0, SeekOrigin.Begin);
+ stream.Seek(0, SeekOrigin.Begin);
var actual = await protocol.ReadDoubleAsync(default);
@@ -445,6 +442,38 @@ public async Task WriteReadDouble_Test(Type protocolType)
}
}
+ [DataTestMethod]
+ [DataRow(typeof(TBinaryProtocol))]
+ [DataRow(typeof(TCompactProtocol))]
+ [DataRow(typeof(TJsonProtocol))]
+ public async Task WriteReadUuid_Test(Type protocolType)
+ {
+ var expected = new Guid("{00112233-4455-6677-8899-aabbccddeeff}");
+
+ try
+ {
+ var tuple = GetProtocolInstance(protocolType);
+ using (var stream = tuple.Stream)
+ {
+ var protocol = tuple.Protocol;
+
+ await protocol.WriteUuidAsync(expected, default);
+ await tuple.Transport.FlushAsync(default);
+
+ stream.Seek(0, SeekOrigin.Begin);
+
+ var actual = await protocol.ReadUuidAsync(default);
+
+ var result = _compareLogic.Compare(expected, actual);
+ Assert.IsTrue(result.AreEqual, result.DifferencesString);
+ }
+ }
+ catch (Exception e)
+ {
+ throw new Exception($"Exception during testing of protocol: {protocolType.FullName}", e);
+ }
+ }
+
[DataTestMethod]
[DataRow(typeof(TBinaryProtocol))]
[DataRow(typeof(TCompactProtocol))]
@@ -463,7 +492,7 @@ public async Task WriteReadString_Test(Type protocolType)
await protocol.WriteStringAsync(expected, default);
await tuple.Transport.FlushAsync(default);
- stream?.Seek(0, SeekOrigin.Begin);
+ stream.Seek(0, SeekOrigin.Begin);
var actual = await protocol.ReadStringAsync(default);
@@ -495,7 +524,7 @@ public async Task WriteReadBinary_Test(Type protocolType)
await protocol.WriteBinaryAsync(expected, default);
await tuple.Transport.FlushAsync(default);
- stream?.Seek(0, SeekOrigin.Begin);
+ stream.Seek(0, SeekOrigin.Begin);
var actual = await protocol.ReadBinaryAsync(default);
@@ -508,16 +537,5 @@ public async Task WriteReadBinary_Test(Type protocolType)
throw new Exception($"Exception during testing of protocol: {protocolType.FullName}", e);
}
}
-
- private record struct ProtocolTransportStack(Stream Stream, TTransport Transport, TProtocol Protocol);
-
- private static ProtocolTransportStack GetProtocolInstance(Type protocolType)
- {
- var memoryStream = new MemoryStream();
- var streamClientTransport = new TStreamTransport(memoryStream, memoryStream,Configuration);
- if( Activator.CreateInstance(protocolType, streamClientTransport) is TProtocol protocol)
- return new ProtocolTransportStack(memoryStream, streamClientTransport, protocol);
- throw new Exception("Unexpected");
- }
}
}
diff --git a/lib/netstd/Tests/Thrift.IntegrationTests/Protocols/TestBase.cs b/lib/netstd/Tests/Thrift.IntegrationTests/Protocols/TestBase.cs
new file mode 100644
index 00000000000..5cbdea9bdf4
--- /dev/null
+++ b/lib/netstd/Tests/Thrift.IntegrationTests/Protocols/TestBase.cs
@@ -0,0 +1,48 @@
+// 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.
+
+using KellermanSoftware.CompareNetObjects;
+using System;
+using System.Collections.Generic;
+using System.IO;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using Thrift.Protocol;
+using Thrift.Transport;
+using Thrift.Transport.Client;
+
+namespace Thrift.IntegrationTests.Protocols
+{
+ public class TestBase
+ {
+ protected readonly CompareLogic _compareLogic = new();
+ protected static readonly TConfiguration Configuration = new();
+
+
+ protected record struct ProtocolTransportStack(Stream Stream, TTransport Transport, TProtocol Protocol);
+
+ protected static ProtocolTransportStack GetProtocolInstance(Type protocolType)
+ {
+ var memoryStream = new MemoryStream();
+ var streamClientTransport = new TStreamTransport(memoryStream, memoryStream, Configuration);
+ if (Activator.CreateInstance(protocolType, streamClientTransport) is TProtocol protocol)
+ return new ProtocolTransportStack(memoryStream, streamClientTransport, protocol);
+ throw new Exception("Unexpected");
+ }
+ }
+}