diff --git a/test/Test.dpr b/test/Test.dpr new file mode 100644 index 0000000..8577862 --- /dev/null +++ b/test/Test.dpr @@ -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. + diff --git a/test/Test.dproj b/test/Test.dproj new file mode 100644 index 0000000..f078823 --- /dev/null +++ b/test/Test.dproj @@ -0,0 +1,105 @@ + + + {788FDD25-ADC6-4D11-B039-557A5E1D1F02} + Test.dpr + Debug + DCC32 + 12.0 + + + true + + + true + Base + true + + + true + Base + true + + + Test.exe + 00400000 + ../;$(DCC_UnitSearchPath) + WinTypes=Windows;WinProcs=Windows;$(DCC_UnitAlias) + x86 + false + false + false + false + false + + + false + RELEASE;$(DCC_Define) + 0 + false + + + DEBUG;$(DCC_Define) + + + + MainSource + + + + Base + + + Cfg_2 + Base + + + Cfg_1 + Base + + + + + Delphi.Personality.12 + VCLApplication + + + + Test.dpr + + + False + True + False + + + False + False + 1 + 0 + 0 + 0 + False + False + False + False + False + 1046 + 1252 + + + + + 1.0.0.0 + + + + + + 1.0.0.0 + + + + + 12 + + diff --git a/test/Test.dproj.local b/test/Test.dproj.local new file mode 100644 index 0000000..a4302e9 --- /dev/null +++ b/test/Test.dproj.local @@ -0,0 +1,7 @@ + + + + 2013/10/28 21:31:11.937.dproj,D:\TMongoWire\test\TMongoWire.dproj=D:\TMongoWire\test\Teste.dproj + 2013/10/28 21:31:16.644.dproj,D:\TMongoWire\test\Teste.dproj=D:\TMongoWire\test\Test.dproj + + diff --git a/test/Test.identcache b/test/Test.identcache new file mode 100644 index 0000000..e72ce7f Binary files /dev/null and b/test/Test.identcache differ diff --git a/test/Test.res b/test/Test.res new file mode 100644 index 0000000..cf557b6 Binary files /dev/null and b/test/Test.res differ diff --git a/test/TestBSONUtils.pas b/test/TestBSONUtils.pas new file mode 100644 index 0000000..ce009ac --- /dev/null +++ b/test/TestBSONUtils.pas @@ -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. + + + + + + diff --git a/test/dunit.ini b/test/dunit.ini new file mode 100644 index 0000000..820662e --- /dev/null +++ b/test/dunit.ini @@ -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 +