Skip to content
Open
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
25 changes: 25 additions & 0 deletions test/Test.dpr
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
program Test;


{$IFDEF CONSOLE_TESTRUNNER}
{$APPTYPE CONSOLE}
{$ENDIF}

uses
Forms,
TestFramework,
GUITestRunner,
TextTestRunner,
TestBSONUtils in 'TestBSONUtils.pas';

{$R *.RES}

begin
Application.Initialize;
if IsConsole then
with TextTestRunner.RunRegisteredTests do
Free
else
GUITestRunner.RunRegisteredTests;
end.

105 changes: 105 additions & 0 deletions test/Test.dproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
 <Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<ProjectGuid>{788FDD25-ADC6-4D11-B039-557A5E1D1F02}</ProjectGuid>
<MainSource>Test.dpr</MainSource>
<Config Condition="'$(Config)'==''">Debug</Config>
<DCC_DCCCompiler>DCC32</DCC_DCCCompiler>
<ProjectVersion>12.0</ProjectVersion>
</PropertyGroup>
<PropertyGroup Condition="'$(Config)'=='Base' or '$(Base)'!=''">
<Base>true</Base>
</PropertyGroup>
<PropertyGroup Condition="'$(Config)'=='Release' or '$(Cfg_1)'!=''">
<Cfg_1>true</Cfg_1>
<CfgParent>Base</CfgParent>
<Base>true</Base>
</PropertyGroup>
<PropertyGroup Condition="'$(Config)'=='Debug' or '$(Cfg_2)'!=''">
<Cfg_2>true</Cfg_2>
<CfgParent>Base</CfgParent>
<Base>true</Base>
</PropertyGroup>
<PropertyGroup Condition="'$(Base)'!=''">
<DCC_DependencyCheckOutputName>Test.exe</DCC_DependencyCheckOutputName>
<DCC_ImageBase>00400000</DCC_ImageBase>
<DCC_UnitSearchPath>../;$(DCC_UnitSearchPath)</DCC_UnitSearchPath>
<DCC_UnitAlias>WinTypes=Windows;WinProcs=Windows;$(DCC_UnitAlias)</DCC_UnitAlias>
<DCC_Platform>x86</DCC_Platform>
<DCC_N>false</DCC_N>
<DCC_S>false</DCC_S>
<DCC_K>false</DCC_K>
<DCC_E>false</DCC_E>
<DCC_F>false</DCC_F>
</PropertyGroup>
<PropertyGroup Condition="'$(Cfg_1)'!=''">
<DCC_LocalDebugSymbols>false</DCC_LocalDebugSymbols>
<DCC_Define>RELEASE;$(DCC_Define)</DCC_Define>
<DCC_SymbolReferenceInfo>0</DCC_SymbolReferenceInfo>
<DCC_DebugInformation>false</DCC_DebugInformation>
</PropertyGroup>
<PropertyGroup Condition="'$(Cfg_2)'!=''">
<DCC_Define>DEBUG;$(DCC_Define)</DCC_Define>
</PropertyGroup>
<ItemGroup>
<DelphiCompile Include="Test.dpr">
<MainSource>MainSource</MainSource>
</DelphiCompile>
<DCCReference Include="TestBSONUtils.pas"/>
<BuildConfiguration Include="Base">
<Key>Base</Key>
</BuildConfiguration>
<BuildConfiguration Include="Debug">
<Key>Cfg_2</Key>
<CfgParent>Base</CfgParent>
</BuildConfiguration>
<BuildConfiguration Include="Release">
<Key>Cfg_1</Key>
<CfgParent>Base</CfgParent>
</BuildConfiguration>
</ItemGroup>
<Import Project="$(BDS)\Bin\CodeGear.Delphi.Targets" Condition="Exists('$(BDS)\Bin\CodeGear.Delphi.Targets')"/>
<ProjectExtensions>
<Borland.Personality>Delphi.Personality.12</Borland.Personality>
<Borland.ProjectType>VCLApplication</Borland.ProjectType>
<BorlandProject>
<Delphi.Personality>
<Source>
<Source Name="MainSource">Test.dpr</Source>
</Source>
<Parameters>
<Parameters Name="UseLauncher">False</Parameters>
<Parameters Name="LoadAllSymbols">True</Parameters>
<Parameters Name="LoadUnspecifiedSymbols">False</Parameters>
</Parameters>
<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">1046</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>
</Delphi.Personality>
</BorlandProject>
<ProjectFileVersion>12</ProjectFileVersion>
</ProjectExtensions>
</Project>
7 changes: 7 additions & 0 deletions test/Test.dproj.local
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<BorlandProject>
<Transactions>
<Transaction>2013/10/28 21:31:11.937.dproj,D:\TMongoWire\test\TMongoWire.dproj=D:\TMongoWire\test\Teste.dproj</Transaction>
<Transaction>2013/10/28 21:31:16.644.dproj,D:\TMongoWire\test\Teste.dproj=D:\TMongoWire\test\Test.dproj</Transaction>
</Transactions>
</BorlandProject>
Binary file added test/Test.identcache
Binary file not shown.
Binary file added test/Test.res
Binary file not shown.
227 changes: 227 additions & 0 deletions test/TestBSONUtils.pas
Original file line number Diff line number Diff line change
@@ -0,0 +1,227 @@
// Test methods bsonUtils.pas
unit TestBSONUtils;

interface

uses
TestFramework,
bsonDoc,
bsonUtils;

type
TTestBSONUtils_BsonToJson = class(TTestCase)
private
d: IBSONDocument;
JSON: string;
published
procedure TestBsonToJsonBasicStructure();

procedure TestBsonToJsonComplex02();
procedure TestBsonToJsonComplex03();
procedure TestBsonToJsonComplex04();
procedure TestBsonToJsonComplex05();
procedure TestBsonToJsonComplex06();
procedure TestBsonToJsonComplex07();
end;

TTestBSONUtils_JsonToBson = class(TTestCase)
end;
TTestBSONUtils_JsonIntoBson = class(TTestCase)
end;


implementation

uses
Variants,
SysUtils;

{ TTestBSONUtils }

procedure TTestBSONUtils_BsonToJson.TestBsonToJsonComplex02;
begin
d:= BSON([
'Company','XYZ Company',
'Address','XYZ Address',
'Phones',VarArrayOf([
BSON(['number','714-999-9999', 'type','business']),
BSON(['number','714-987-6533', 'type','cell'])
])]);

JSON:=
'{"Company":"XYZ Company",' +
'"Address":"XYZ Address",' +
'"Phones":[' +
'{"number":"714-999-9999","type":"business"},' +
'{"number":"714-987-6533","type":"cell"}'+
']}';

CheckEqualsString( JSON, BsonToJson( d ) );
end;

procedure TTestBSONUtils_BsonToJson.TestBsonToJsonComplex03;
begin
d:= BSON([ 'movies' ,
VarArrayOf( [
BSON([ 'title', 'Shut Up and Play the Hits' , 'year', 2012 ]),
BSON([ 'title', 'John Morre no Final' , 'year', 2012 ]),
BSON([ 'title', 'The Comedy' , 'year', 2012 ]),
BSON([ 'title', 'Bem-vindo aos 40' , 'year', 2012 ]),
BSON([ 'title', 'Cop Land' , 'year', 1997])
])
]);

JSON:=
'{"movies":[' +
'{"title":"Shut Up and Play the Hits","year":2012},' +
'{"title":"John Morre no Final","year":2012},' +
'{"title":"The Comedy","year":2012},' +
'{"title":"Bem-vindo aos 40","year":2012},' +
'{"title":"Cop Land","year":1997}' +
']}';


CheckEqualsString( JSON, BsonToJson( d ) );

end;

procedure TTestBSONUtils_BsonToJson.TestBsonToJsonComplex04;
begin
d:=BSON([
'Name', 'Johni',
'Sports', VarArrayOf( ['football', 'volleyball', 'chess'] )
]);

JSON:=
'{"Name":"Johni",' +
'"Sports":["football","volleyball","chess"]' +
'}';

CheckEqualsString( JSON, BsonToJson( d ) );

end;

procedure TTestBSONUtils_BsonToJson.TestBsonToJsonComplex05;
begin

d := BSON([
'name' , 'Johni Douglas Marangon',
'age' , 27,
'sex' , 'M',
'salary' , 1500,
'registered' , true,
'favorites' , BSON([ 'color' , 'Red' , 'sport' , 'Soccer', 'food' , 'Spaghetti'] )
]);


JSON :=
'{"name":"Johni Douglas Marangon",' +
'"age":27,' +
'"sex":"M",' +
'"salary":1500,' +
'"registered":true,' +
'"favorites":{' +
'"color":"Red",' +
'"sport":"Soccer",' +
'"food":"Spaghetti"' +
'}' +
'}';

CheckEqualsString(JSON, BsonToJson(d));

end;

procedure TTestBSONUtils_BsonToJson.TestBsonToJsonBasicStructure;
begin
d :=
BSON([
'Name', 'Johni Douglas Marangon',
'Phone', 4912345678,
'Sex' , 'M',
'BirthDate', StrToDate( '28/06/1986' ),
'Registered', True
]);

JSON :=
'{' +
'"Name":"Johni Douglas Marangon",' +
'"Phone":4912345678,' +
'"Sex":"M",' +
'"BirthDate":"1986-06-28T00:00:00.000",' +
'"Registered":true' +

'}';

CheckEqualsString(JSON, BsonToJson(d));

end;


procedure TTestBSONUtils_BsonToJson.TestBsonToJsonComplex07;
begin
d:= BSON([
'test',
VarArrayOf([
BSON ([ 'category', 'PHP', 'result', VarArrayOf( [ BSON([ 'name' ,'One', 'score', 90 ]), BSON([ 'name' ,'Two', 'score', 75 ]) ] ) ] ),
BSON ([ 'category', 'Delphi', 'result', VarArrayOf( [ BSON([ 'name' ,'One', 'score', 96 ]), BSON([ 'name' ,'Two', 'score', 52 ]) ] ) ] ),
BSON ([ 'category', 'Java', 'result', VarArrayOf( [ BSON([ 'name' ,'One', 'score', 74 ]), BSON([ 'name' ,'Two', 'score', 49 ]) ] ) ] )
])
]);

JSON:=
'{'+
'"test":[' +
'{"category":"PHP",' +
'"result":[{"name":"One","score":90},' +
'{"name":"Two","score":75}]},' +
'{"category":"Delphi",' +
'"result":[{"name":"One","score":96},' +
'{"name":"Two","score":52}]},' +
'{"category":"Java",'+
'"result":[{"name":"One","score":74},' +
'{"name":"Two","score":49}]}' +
']' +
'}';

CheckEqualsString( JSON, BsonToJson( d ) );

end;

procedure TTestBSONUtils_BsonToJson.TestBsonToJsonComplex06;
begin
d:= BSON( [
'menu',
BSON(
[ 'header' ,'Viewer' ,
'itens', VarArrayOf([
BSON([ 'id', 'Open' ]),
BSON([ 'id', 'OpenNew', 'label', 'Open New' ]),
BSON([ 'id', 'ZoonIn', 'label', 'Zoon In' , 'position', 10 ])
])
])
]);

JSON:=
'{"menu":{"header":"Viewer",' +
'"itens":[' +
'{"id":"Open"},' +
'{"id":"OpenNew","label":"Open New"},' +
'{"id":"ZoonIn","label":"Zoon In","position":10}' +
']'+
'}}';

CheckEqualsString( JSON, BsonToJson( d ) );

end;

initialization

RegisterTest(TTestBSONUtils_BsonToJson.Suite);

end.






26 changes: 26 additions & 0 deletions test/dunit.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
[GUITestRunner Config]
AutoSave=1
Left=110
Top=110
Width=500
Height=500
Maximized=1
UseRegistry=0
ResultsPanel.Height=174
ErrorMessage.Height=75
ErrorMessage.Visible=1
FailureList.ColumnWidth[0]=120
FailureList.ColumnWidth[1]=100
FailureList.ColumnWidth[2]=200
FailureList.ColumnWidth[3]=1488
HideTestNodesOnOpen=0
BreakOnFailures=0
FailOnNoChecksExecuted=0
FailOnMemoryLeaked=0
IgnoreSetUpTearDownLeaks=0
ReportMemoryLeakTypes=0
SelectTestedNode=1
WarnOnFailTestOverride=0
PopupX=350
PopupY=30