Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion lib/delphi/src/Thrift.Transport.pas
Original file line number Diff line number Diff line change
Expand Up @@ -1446,8 +1446,11 @@ procedure TBufferedTransportImpl.CheckReadBytesAvailable( const value : Int64);
{ TBufferedTransportImpl.TFactory }

function TBufferedTransportImpl.TFactory.GetTransport( const aTransport: ITransport): ITransport;
var stream : IStreamTransport;
begin
Result := TFramedTransportImpl.Create( aTransport);
if Supports( aTransport, IStreamTransport, stream)
then Result := TBufferedTransportImpl.Create( stream)
else raise TTransportExceptionBadArgs.Create('TBufferedTransportImpl requires an IStreamTransport');
end;


Expand Down
37 changes: 35 additions & 2 deletions lib/delphi/test/serializer/TestSerializer.Tests.pas
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ TTestSerializer = class //extends TestCase {
class function DataPtrOf( const bytes : IThriftBytes) : Pointer; overload; inline;

procedure Test_Serializer_Deserializer;
procedure Test_TransportFactories;
procedure Test_COM_Types;
procedure Test_ThriftBytesCTORs;
procedure Test_Equal;
Expand Down Expand Up @@ -437,8 +438,9 @@ 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)
// protocol conformity tests, on the plain wire format, which a buffered transport does not change
if (method = TMethod.mt_Bytes)
and ((factory.trans = nil) or ((factory.trans as TObject) is TBufferedTransportImpl.TFactory))
then Test_ProtocolConformity( factory, stream);

// normal objects
Expand Down Expand Up @@ -803,10 +805,41 @@ procedure TTestSerializer.Test_Equal;
end;


procedure TTestSerializer.Test_TransportFactories;
var config : IThriftConfiguration;
stm : IStreamTransport;
framed : ITransport;
trans : ITransport;
factory : ITransportFactory;
begin
config := TThriftConfigurationImpl.Create;
stm := TStreamTransportImpl.Create( nil, nil, config);

factory := TBufferedTransportImpl.TFactory.Create;
trans := factory.GetTransport( stm);
ASSERT( (trans as TObject) is TBufferedTransportImpl);

factory := TFramedTransportImpl.TFactory.Create;
framed := factory.GetTransport( stm);
ASSERT( (framed as TObject) is TFramedTransportImpl);

// a buffered transport needs the stream interface of the transport below it
factory := TBufferedTransportImpl.TFactory.Create;
try
factory.GetTransport( framed);
raise EInOutError.Create('Expected exception not thrown?');
except
on e:TTransportExceptionBadArgs do {expected};
on e:Exception do raise; // unexpected
end;
end;


procedure TTestSerializer.RunTests;
begin
try
Test_Serializer_Deserializer;
Test_TransportFactories;
Test_COM_Types;
Test_ThriftBytesCTORs;
Test_Equal;
Expand Down
Loading