THRIFT-5620 Option to force usage of COM types to allow for cross-module references
Client: Delphi
Patch: Jens Geyer
diff --git a/lib/delphi/test/serializer/SerializerData.dpr b/lib/delphi/test/serializer/SerializerData.dpr
new file mode 100644
index 0000000..92ed00b
--- /dev/null
+++ b/lib/delphi/test/serializer/SerializerData.dpr
@@ -0,0 +1,82 @@
+library SerializerData;
+(*
+ * 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.
+ *)
+
+uses
+ Classes,
+ Windows,
+ SysUtils,
+ Generics.Collections,
+ Thrift in '..\..\src\Thrift.pas',
+ Thrift.Exception in '..\..\src\Thrift.Exception.pas',
+ Thrift.Socket in '..\..\src\Thrift.Socket.pas',
+ Thrift.Transport in '..\..\src\Thrift.Transport.pas',
+ Thrift.Protocol in '..\..\src\Thrift.Protocol.pas',
+ Thrift.Protocol.JSON in '..\..\src\Thrift.Protocol.JSON.pas',
+ Thrift.Protocol.Compact in '..\..\src\Thrift.Protocol.Compact.pas',
+ Thrift.Collections in '..\..\src\Thrift.Collections.pas',
+ Thrift.Configuration in '..\..\src\Thrift.Configuration.pas',
+ Thrift.Server in '..\..\src\Thrift.Server.pas',
+ Thrift.Utils in '..\..\src\Thrift.Utils.pas',
+ Thrift.Serializer in '..\..\src\Thrift.Serializer.pas',
+ Thrift.Stream in '..\..\src\Thrift.Stream.pas',
+ Thrift.WinHTTP in '..\..\src\Thrift.WinHTTP.pas',
+ Thrift.TypeRegistry in '..\..\src\Thrift.TypeRegistry.pas',
+ System_ in 'gen-delphi\System_.pas',
+ SysUtils_ in 'gen-delphi\SysUtils_.pas',
+ DebugProtoTest in 'gen-delphi\DebugProtoTest.pas',
+ TestSerializer.Data in 'TestSerializer.Data.pas';
+
+{$R *.res}
+
+function CreateOneOfEach : IOneOfEach; stdcall;
+begin
+ result := Fixtures.CreateOneOfEach;
+end;
+
+
+function CreateNesting : INesting; stdcall;
+begin
+ result := Fixtures.CreateNesting;
+end;
+
+
+function CreateHolyMoley : IHolyMoley; stdcall;
+begin
+ result := Fixtures.CreateHolyMoley;
+end;
+
+
+function CreateCompactProtoTestStruct : ICompactProtoTestStruct; stdcall;
+begin
+ result := Fixtures.CreateCompactProtoTestStruct;
+end;
+
+
+exports
+ CreateOneOfEach,
+ CreateNesting,
+ CreateHolyMoley,
+ CreateCompactProtoTestStruct;
+
+begin
+ IsMultiThread := TRUE;
+ ASSERT( cDebugProtoTest_Option_COM_types);
+ ASSERT( cSystem__Option_COM_types);
+end.
diff --git a/lib/delphi/test/serializer/SerializerData.dproj b/lib/delphi/test/serializer/SerializerData.dproj
new file mode 100644
index 0000000..cfc27f8
--- /dev/null
+++ b/lib/delphi/test/serializer/SerializerData.dproj
@@ -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.
+-->
+ <Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <PropertyGroup>
+ <ProjectGuid>{B523D1D7-2C9A-4B39-A6CF-69EF536D5079}</ProjectGuid>
+ <MainSource>SerializerData.dpr</MainSource>
+ <ProjectVersion>12.3</ProjectVersion>
+ <Basis>True</Basis>
+ <Config Condition="'$(Config)'==''">Debug</Config>
+ <Platform>Win32</Platform>
+ <AppType>Library</AppType>
+ <FrameworkType>None</FrameworkType>
+ <DCC_DCCCompiler>DCC32</DCC_DCCCompiler>
+ </PropertyGroup>
+ <PropertyGroup Condition="'$(Config)'=='Basis' or '$(Base)'!=''">
+ <Base>true</Base>
+ </PropertyGroup>
+ <PropertyGroup Condition="'$(Config)'=='Debug' or '$(Cfg_1)'!=''">
+ <Cfg_1>true</Cfg_1>
+ <CfgParent>Base</CfgParent>
+ <Base>true</Base>
+ </PropertyGroup>
+ <PropertyGroup Condition="'$(Config)'=='Release' or '$(Cfg_2)'!=''">
+ <Cfg_2>true</Cfg_2>
+ <CfgParent>Base</CfgParent>
+ <Base>true</Base>
+ </PropertyGroup>
+ <PropertyGroup Condition="'$(Base)'!=''">
+ <DCC_DcuOutput>.\$(Config)\$(Platform)</DCC_DcuOutput>
+ <DCC_E>false</DCC_E>
+ <DCC_ImageBase>00400000</DCC_ImageBase>
+ <DCC_UnitAlias>WinTypes=Windows;WinProcs=Windows;DbiTypes=BDE;DbiProcs=BDE;$(DCC_UnitAlias)</DCC_UnitAlias>
+ <DCC_ExeOutput>bin\$(Config)\$(Platform)</DCC_ExeOutput>
+ <DCC_S>false</DCC_S>
+ <GenDll>true</GenDll>
+ <DCC_N>false</DCC_N>
+ <DCC_F>false</DCC_F>
+ <DCC_K>false</DCC_K>
+ </PropertyGroup>
+ <PropertyGroup Condition="'$(Cfg_1)'!=''">
+ <DCC_Define>DEBUG;$(DCC_Define)</DCC_Define>
+ <DCC_Optimize>false</DCC_Optimize>
+ <DCC_GenerateStackFrames>true</DCC_GenerateStackFrames>
+ </PropertyGroup>
+ <PropertyGroup Condition="'$(Cfg_2)'!=''">
+ <DCC_LocalDebugSymbols>false</DCC_LocalDebugSymbols>
+ <DCC_Define>RELEASE;$(DCC_Define)</DCC_Define>
+ <DCC_SymbolReferenceInfo>0</DCC_SymbolReferenceInfo>
+ <DCC_DebugInformation>false</DCC_DebugInformation>
+ </PropertyGroup>
+ <ItemGroup>
+ <DelphiCompile Include="SerializerData.dpr">
+ <MainSource>MainSource</MainSource>
+ </DelphiCompile>
+ <DCCReference Include="..\..\src\Thrift.pas"/>
+ <DCCReference Include="..\..\src\Thrift.Exception.pas"/>
+ <DCCReference Include="..\..\src\Thrift.Socket.pas"/>
+ <DCCReference Include="..\..\src\Thrift.Transport.pas"/>
+ <DCCReference Include="..\..\src\Thrift.Protocol.pas"/>
+ <DCCReference Include="..\..\src\Thrift.Protocol.JSON.pas"/>
+ <DCCReference Include="..\..\src\Thrift.Protocol.Compact.pas"/>
+ <DCCReference Include="..\..\src\Thrift.Collections.pas"/>
+ <DCCReference Include="..\..\src\Thrift.Configuration.pas"/>
+ <DCCReference Include="..\..\src\Thrift.Server.pas"/>
+ <DCCReference Include="..\..\src\Thrift.Utils.pas"/>
+ <DCCReference Include="..\..\src\Thrift.Serializer.pas"/>
+ <DCCReference Include="..\..\src\Thrift.Stream.pas"/>
+ <DCCReference Include="..\..\src\Thrift.WinHTTP.pas"/>
+ <DCCReference Include="..\..\src\Thrift.TypeRegistry.pas"/>
+ <DCCReference Include="gen-delphi\System_.pas"/>
+ <DCCReference Include="gen-delphi\SysUtils_.pas"/>
+ <DCCReference Include="gen-delphi\DebugProtoTest.pas"/>
+ <DCCReference Include="TestSerializer.Data.pas"/>
+ <BuildConfiguration Include="Release">
+ <Key>Cfg_2</Key>
+ <CfgParent>Base</CfgParent>
+ </BuildConfiguration>
+ <BuildConfiguration Include="Basis">
+ <Key>Base</Key>
+ </BuildConfiguration>
+ <BuildConfiguration Include="Debug">
+ <Key>Cfg_1</Key>
+ <CfgParent>Base</CfgParent>
+ </BuildConfiguration>
+ </ItemGroup>
+ <Import Condition="Exists('$(BDS)\Bin\CodeGear.Delphi.Targets')" Project="$(BDS)\Bin\CodeGear.Delphi.Targets"/>
+ <Import Condition="Exists('$(APPDATA)\Embarcadero\$(BDSAPPDATABASEDIR)\$(PRODUCTVERSION)\UserTools.proj')" Project="$(APPDATA)\Embarcadero\$(BDSAPPDATABASEDIR)\$(PRODUCTVERSION)\UserTools.proj"/>
+ <PropertyGroup>
+ <PreBuildEvent><![CDATA[thrift.exe -r -gen delphi:com_types ..\keywords\ReservedKeywords.thrift
+thrift.exe -r -gen delphi:com_types ..\..\..\..\test\DebugProtoTest.thrift]]></PreBuildEvent>
+ </PropertyGroup>
+ <ProjectExtensions>
+ <Borland.Personality>Delphi.Personality.12</Borland.Personality>
+ <Borland.ProjectType/>
+ <BorlandProject>
+ <Delphi.Personality>
+ <VersionInfo>
+ <VersionInfo Name="IncludeVerInfo">False</VersionInfo>
+ <VersionInfo Name="AutoIncBuild">False</VersionInfo>
+ <VersionInfo Name="MajorVer">1</VersionInfo>
+ <VersionInfo Name="MinorVer">0</VersionInfo>
+ <VersionInfo Name="Release">0</VersionInfo>
+ <VersionInfo Name="Build">0</VersionInfo>
+ <VersionInfo Name="Debug">False</VersionInfo>
+ <VersionInfo Name="PreRelease">False</VersionInfo>
+ <VersionInfo Name="Special">False</VersionInfo>
+ <VersionInfo Name="Private">False</VersionInfo>
+ <VersionInfo Name="DLL">False</VersionInfo>
+ <VersionInfo Name="Locale">1031</VersionInfo>
+ <VersionInfo Name="CodePage">1252</VersionInfo>
+ </VersionInfo>
+ <VersionInfoKeys>
+ <VersionInfoKeys Name="CompanyName"/>
+ <VersionInfoKeys Name="FileDescription"/>
+ <VersionInfoKeys Name="FileVersion">1.0.0.0</VersionInfoKeys>
+ <VersionInfoKeys Name="InternalName"/>
+ <VersionInfoKeys Name="LegalCopyright"/>
+ <VersionInfoKeys Name="LegalTrademarks"/>
+ <VersionInfoKeys Name="OriginalFilename"/>
+ <VersionInfoKeys Name="ProductName"/>
+ <VersionInfoKeys Name="ProductVersion">1.0.0.0</VersionInfoKeys>
+ <VersionInfoKeys Name="Comments"/>
+ </VersionInfoKeys>
+ <Source>
+ <Source Name="MainSource">SerializerData.dpr</Source>
+ </Source>
+ </Delphi.Personality>
+ <Platforms>
+ <Platform value="Win32">True</Platform>
+ </Platforms>
+ </BorlandProject>
+ <ProjectFileVersion>12</ProjectFileVersion>
+ </ProjectExtensions>
+ </Project>
diff --git a/lib/delphi/test/serializer/SerializerData.res b/lib/delphi/test/serializer/SerializerData.res
new file mode 100644
index 0000000..231eb70
--- /dev/null
+++ b/lib/delphi/test/serializer/SerializerData.res
Binary files differ
diff --git a/lib/delphi/test/serializer/TestSerializer.Data.pas b/lib/delphi/test/serializer/TestSerializer.Data.pas
index af366fd..4b8cc66 100644
--- a/lib/delphi/test/serializer/TestSerializer.Data.pas
+++ b/lib/delphi/test/serializer/TestSerializer.Data.pas
@@ -23,6 +23,7 @@
uses
SysUtils,
+ Thrift.Protocol,
Thrift.Collections,
DebugProtoTest;
@@ -194,6 +195,8 @@
{$IF cDebugProtoTest_Option_AnsiStr_Binary}
result.SetBase64('base64');
+ {$ELSEIF cDebugProtoTest_Option_COM_Types}
+ result.SetBase64( TThriftBytesImpl.Create( TEncoding.UTF8.GetBytes('base64')));
{$ELSE}
result.SetBase64( TEncoding.UTF8.GetBytes('base64'));
{$IFEND}
@@ -216,8 +219,10 @@
class function Fixtures.CreateHolyMoley : IHolyMoley;
+type
+ TStringType = {$IF cDebugProtoTest_Option_COM_Types} WideString {$ELSE} String {$IFEND};
var big : IThriftList<IOneOfEach>;
- stage1 : IThriftList<String>;
+ stage1 : IThriftList<TStringType>;
stage2 : IThriftList<IBonk>;
b : IBonk;
begin
@@ -230,23 +235,23 @@
result.Big[0].setA_bite( $22);
result.Big[0].setA_bite( $23);
- result.Contain := TThriftHashSetImpl< IThriftList<string>>.Create;
- stage1 := TThriftListImpl<String>.Create;
+ result.Contain := TThriftHashSetImpl< IThriftList<TStringType>>.Create;
+ stage1 := TThriftListImpl<TStringType>.Create;
stage1.add( 'and a one');
stage1.add( 'and a two');
result.Contain.add( stage1);
- stage1 := TThriftListImpl<String>.Create;
+ stage1 := TThriftListImpl<TStringType>.Create;
stage1.add( 'then a one, two');
stage1.add( 'three!');
stage1.add( 'FOUR!!');
result.Contain.add( stage1);
- stage1 := TThriftListImpl<String>.Create;
+ stage1 := TThriftListImpl<TStringType>.Create;
result.Contain.add( stage1);
stage2 := TThriftListImpl<IBonk>.Create;
- result.Bonks := TThriftDictionaryImpl< String, IThriftList< IBonk>>.Create;
+ result.Bonks := TThriftDictionaryImpl< TStringType, IThriftList< IBonk>>.Create;
// one empty
result.Bonks.Add( 'zero', stage2);
@@ -342,6 +347,8 @@
{$IF cDebugProtoTest_Option_AnsiStr_Binary}
result.A_binary := AnsiString( #0#1#2#3#4#5#6#7#8);
+ {$ELSEIF cDebugProtoTest_Option_COM_Types}
+ result.A_binary := TThriftBytesImpl.Create( TEncoding.UTF8.GetBytes( #0#1#2#3#4#5#6#7#8));
{$ELSE}
result.A_binary := TEncoding.UTF8.GetBytes( #0#1#2#3#4#5#6#7#8);
{$IFEND}
diff --git a/lib/delphi/test/serializer/TestSerializer.Tests.pas b/lib/delphi/test/serializer/TestSerializer.Tests.pas
index 83d67b1..443a22d 100644
--- a/lib/delphi/test/serializer/TestSerializer.Tests.pas
+++ b/lib/delphi/test/serializer/TestSerializer.Tests.pas
@@ -41,8 +41,7 @@
Thrift.WinHTTP,
Thrift.TypeRegistry,
System_,
- DebugProtoTest,
- TestSerializer.Data;
+ DebugProtoTest;
type
@@ -58,7 +57,7 @@
mt_Stream
);
- private
+ strict private
FProtocols : TList< TFactoryPair>;
procedure AddFactoryCombination( const aProto : IProtocolFactory; const aTrans : ITransportFactory);
class function UserFriendlyName( const factory : TFactoryPair) : string; overload;
@@ -73,7 +72,14 @@
class procedure ValidateReadToEnd( const input : TBytes; const serial : TDeserializer); overload;
class procedure ValidateReadToEnd( const input : TStream; const serial : TDeserializer); overload;
+ class function LengthOf( const bytes : TBytes) : Integer; overload; inline;
+ class function LengthOf( const bytes : IThriftBytes) : Integer; overload; inline;
+
+ class function DataPtrOf( const bytes : TBytes) : Pointer; overload; inline;
+ class function DataPtrOf( const bytes : IThriftBytes) : Pointer; overload; inline;
+
procedure Test_Serializer_Deserializer;
+ procedure Test_COM_Types;
procedure Test_OneOfEach( const method : TMethod; const factory : TFactoryPair; const stream : TFileStream);
procedure Test_CompactStruct( const method : TMethod; const factory : TFactoryPair; const stream : TFileStream);
@@ -87,6 +93,12 @@
implementation
+const SERIALIZERDATA_DLL = 'SerializerData.dll';
+function CreateOneOfEach : IOneOfEach; stdcall; external SERIALIZERDATA_DLL;
+function CreateNesting : INesting; stdcall; external SERIALIZERDATA_DLL;
+function CreateHolyMoley : IHolyMoley; stdcall; external SERIALIZERDATA_DLL;
+function CreateCompactProtoTestStruct : ICompactProtoTestStruct; stdcall; external SERIALIZERDATA_DLL;
+
{ TTestSerializer }
@@ -128,13 +140,41 @@
end;
+class function TTestSerializer.LengthOf( const bytes : TBytes) : Integer;
+begin
+ result := Length(bytes);
+end;
+
+
+class function TTestSerializer.LengthOf( const bytes : IThriftBytes) : Integer;
+begin
+ if bytes <> nil
+ then result := bytes.Count
+ else result := 0;
+end;
+
+
+class function TTestSerializer.DataPtrOf( const bytes : TBytes) : Pointer;
+begin
+ result := bytes;
+end;
+
+
+class function TTestSerializer.DataPtrOf( const bytes : IThriftBytes) : Pointer;
+begin
+ if bytes <> nil
+ then result := bytes.QueryRawDataPtr
+ else result := nil;
+end;
+
+
procedure TTestSerializer.Test_OneOfEach( const method : TMethod; const factory : TFactoryPair; const stream : TFileStream);
var tested, correct : IOneOfEach;
bytes : TBytes;
i : Integer;
begin
// write
- tested := Fixtures.CreateOneOfEach;
+ tested := CreateOneOfEach;
case method of
mt_Bytes: bytes := Serialize( tested, factory);
mt_Stream: begin
@@ -158,7 +198,7 @@
end;
// check
- correct := Fixtures.CreateOneOfEach;
+ correct := CreateOneOfEach;
ASSERT( tested.Im_true = correct.Im_true);
ASSERT( tested.Im_false = correct.Im_false);
ASSERT( tested.A_bite = correct.A_bite);
@@ -170,8 +210,8 @@
ASSERT( tested.Zomg_unicode = correct.Zomg_unicode);
ASSERT( tested.What_who = correct.What_who);
- ASSERT( Length(tested.Base64) = Length(correct.Base64));
- ASSERT( CompareMem( @tested.Base64[0], @correct.Base64[0], Length(correct.Base64)));
+ ASSERT( LengthOf(tested.Base64) = LengthOf(correct.Base64));
+ ASSERT( CompareMem( DataPtrOf(tested.Base64), DataPtrOf(correct.Base64), LengthOf(correct.Base64)));
ASSERT( tested.Byte_list.Count = correct.Byte_list.Count);
for i := 0 to tested.Byte_list.Count-1
@@ -192,7 +232,7 @@
bytes : TBytes;
begin
// write
- tested := Fixtures.CreateCompactProtoTestStruct;
+ tested := CreateCompactProtoTestStruct;
case method of
mt_Bytes: bytes := Serialize( tested, factory);
mt_Stream: begin
@@ -216,7 +256,7 @@
end;
// check
- correct := Fixtures.CreateCompactProtoTestStruct;
+ correct := CreateCompactProtoTestStruct;
ASSERT( correct.Field500 = tested.Field500);
ASSERT( correct.Field5000 = tested.Field5000);
ASSERT( correct.Field20000 = tested.Field20000);
@@ -269,10 +309,25 @@
end;
+procedure TTestSerializer.Test_COM_Types;
+var tested : IOneOfEach;
+begin
+ {$IF cDebugProtoTest_Option_COM_types}
+ ASSERT( SizeOf(TSomeEnum) = SizeOf(Int32)); // -> MINENUMSIZE 4
+
+ // try to set values that allocate memory
+ tested := CreateOneOfEach;
+ tested.Zomg_unicode := 'This is a test';
+ tested.Base64 := TThriftBytesImpl.Create( TEncoding.UTF8.GetBytes('abc'));
+ {$IFEND}
+end;
+
+
procedure TTestSerializer.RunTests;
begin
try
Test_Serializer_Deserializer;
+ Test_COM_Types;
except
on e:Exception do begin
Writeln( e.ClassName+': '+ e.Message);
diff --git a/lib/delphi/test/serializer/TestSerializer.dpr b/lib/delphi/test/serializer/TestSerializer.dpr
index 971401e..b78c0db 100644
--- a/lib/delphi/test/serializer/TestSerializer.dpr
+++ b/lib/delphi/test/serializer/TestSerializer.dpr
@@ -44,8 +44,7 @@
System_ in 'gen-delphi\System_.pas',
SysUtils_ in 'gen-delphi\SysUtils_.pas',
DebugProtoTest in 'gen-delphi\DebugProtoTest.pas',
- TestSerializer.Tests in 'TestSerializer.Tests.pas',
- TestSerializer.Data in 'TestSerializer.Data.pas';
+ TestSerializer.Tests in 'TestSerializer.Tests.pas';
var test : TTestSerializer;
diff --git a/lib/delphi/test/serializer/TestSerializer.dproj b/lib/delphi/test/serializer/TestSerializer.dproj
index 5f26264..1d98d3a 100644
--- a/lib/delphi/test/serializer/TestSerializer.dproj
+++ b/lib/delphi/test/serializer/TestSerializer.dproj
@@ -86,7 +86,6 @@
<DCCReference Include="gen-delphi\SysUtils_.pas"/>
<DCCReference Include="gen-delphi\DebugProtoTest.pas"/>
<DCCReference Include="TestSerializer.Tests.pas"/>
- <DCCReference Include="TestSerializer.Data.pas"/>
<BuildConfiguration Include="Debug">
<Key>Cfg_2</Key>
<CfgParent>Base</CfgParent>
@@ -102,8 +101,8 @@
<Import Condition="Exists('$(BDS)\Bin\CodeGear.Delphi.Targets')" Project="$(BDS)\Bin\CodeGear.Delphi.Targets"/>
<Import Condition="Exists('$(APPDATA)\Embarcadero\$(BDSAPPDATABASEDIR)\$(PRODUCTVERSION)\UserTools.proj')" Project="$(APPDATA)\Embarcadero\$(BDSAPPDATABASEDIR)\$(PRODUCTVERSION)\UserTools.proj"/>
<PropertyGroup>
- <PreBuildEvent><![CDATA[thrift.exe -r -gen delphi ..\keywords\ReservedKeywords.thrift
-thrift.exe -r -gen delphi ..\..\..\..\test\DebugProtoTest.thrift]]></PreBuildEvent>
+ <PreBuildEvent><![CDATA[thrift.exe -r -gen delphi:com_types ..\keywords\ReservedKeywords.thrift
+thrift.exe -r -gen delphi:com_types ..\..\..\..\test\DebugProtoTest.thrift]]></PreBuildEvent>
</PropertyGroup>
<ProjectExtensions>
<Borland.Personality>Delphi.Personality.12</Borland.Personality>