From 9758f4fa6a37f8dd4de0724af6a38d4abd06098d Mon Sep 17 00:00:00 2001 From: reiniero Date: Sun, 31 Mar 2013 15:09:47 +0000 Subject: [PATCH] sqldb/dbtestframework fixes: * slight cleanup dbftoolsunit * Fix gui framework selecting old connector after selecting another. * Cosmetic, spelling fixes. git-svn-id: trunk@24090 - --- packages/fcl-db/tests/README.txt | 13 +++++----- packages/fcl-db/tests/bufdatasettoolsunit.pas | 7 +++--- packages/fcl-db/tests/database.ini.txt | 2 +- packages/fcl-db/tests/dbftoolsunit.pas | 24 ++++++++++++------- packages/fcl-db/tests/dbtestframework_gui.lpr | 6 ++++- packages/fcl-db/tests/testdatasources.pas | 4 ++-- packages/fcl-db/tests/toolsunit.pas | 3 ++- 7 files changed, 37 insertions(+), 22 deletions(-) diff --git a/packages/fcl-db/tests/README.txt b/packages/fcl-db/tests/README.txt index 27cbe194a7..0d25179336 100644 --- a/packages/fcl-db/tests/README.txt +++ b/packages/fcl-db/tests/README.txt @@ -8,7 +8,8 @@ Simply add the test* units in this directory to the uses statement of the test runner and all tests will get registered and executed. A simple test runner (dbtestframework.pas) which generates XML output is -included in this directory. +included in this directory. +Additionally, a GUI Lazarus unit (dbtestframework_gui.lpr) is included for convenience. DBTestframework architecture ============================ @@ -31,11 +32,11 @@ They call InternalGetNDataset and InternalGetFieldDataset which should be implem Toolsunit.pas defines some variables for use, e.g. - testValuesCount is the number of records/test values in the FieldDataset dataset - MaxDataset is the same for NDataset. -See e.g. the SQLDBToolsUnit for the implementation for SQL Databases. +See e.g. the SQLDBToolsUnit for the implementation for SQL databases. Tests ===== -In your test units, you can specify that you only want to run for certain groups/connectors. +In your test units, you can specify that you only want it to run for certain groups/connectors. E.g. this example to only run for Bufdataset tests: TTestSpecificTBufDataset = class(TTestCase) ... @@ -58,9 +59,9 @@ The database can be empty: the test suite will create and delete tables etc. in Specifying databases, connector names ===================================== -Which connector is currently used is dependent on the 'database.ini' +Which connector is currently used is determined by the 'database.ini' configuration file. Also some settings which are connector-dependent can be set -in that file. See 'database.ini.txt' for an example. +in that file. See 'database.ini.txt' for a template/example. The connector names to be used are derived from the connector classes. @@ -68,7 +69,7 @@ For example, the SQL RDBMS connector defined in sqldbtoolsunit: - it has this class definition TSQLDBConnector = class(TDBConnector) - its name in database.ini is sqldb -- incidentally, in databases.ini, more parameter such as +- incidentally, in databases.ini, more parameters such as connectorparams=postgresql (which specify db type) are needed The parameters used depend on the connector type (sql,...) diff --git a/packages/fcl-db/tests/bufdatasettoolsunit.pas b/packages/fcl-db/tests/bufdatasettoolsunit.pas index 56445c82e3..f4707c542d 100644 --- a/packages/fcl-db/tests/bufdatasettoolsunit.pas +++ b/packages/fcl-db/tests/bufdatasettoolsunit.pas @@ -1,10 +1,11 @@ unit BufDatasetToolsUnit; { Sets up bufdataset for testing. -Tests expect Get*Dataset tho return a dataset with structure and test data, but closed. +Tests expect Get*Dataset to return a dataset with structure and test data, but closed. A closed BufDataset normally has no data, so these tests won't work. -To circumvent this, this unit saves the dataset contents to file and reloads them on opening using BufDataset persistence mechanism. +To circumvent this, this unit saves the dataset contents to file and reloads them on opening +using the BufDataset persistence mechanism. } {$mode objfpc}{$H+} @@ -64,7 +65,7 @@ end; procedure TbufdatasetDBConnector.CreateNDatasets; begin -// All datasets are created in InternalGet*Dataset + // All datasets are created in InternalGet*Dataset end; procedure TbufdatasetDBConnector.CreateFieldDataset; diff --git a/packages/fcl-db/tests/database.ini.txt b/packages/fcl-db/tests/database.ini.txt index 202a96e8c0..4ce7f636ae 100644 --- a/packages/fcl-db/tests/database.ini.txt +++ b/packages/fcl-db/tests/database.ini.txt @@ -161,7 +161,7 @@ hostname=127.0.0.1 [dbf] connector=dbf -; Give here the path where the *.dbf file can be generated +; The path where the *.dbf file can be generated: name=/tmp ; MemDS in memory dataset: diff --git a/packages/fcl-db/tests/dbftoolsunit.pas b/packages/fcl-db/tests/dbftoolsunit.pas index 4f49a6a4e2..f5ec5a4982 100644 --- a/packages/fcl-db/tests/dbftoolsunit.pas +++ b/packages/fcl-db/tests/dbftoolsunit.pas @@ -1,5 +1,10 @@ unit DBFToolsUnit; +{ Sets up dbf datasets for testing +Tests expect Get*Dataset to return a dataset with structure and test data, but closed. +Because of this, we use file-backed dbfs instead of memory backed dbfs +} + {$IFDEF FPC} {$mode objfpc}{$H+} {$ENDIF} @@ -38,6 +43,9 @@ type implementation +const + FieldDatasetTableName='fpdev_field.db'; + procedure TDBFDBConnector.CreateNDatasets; var countID,n : integer; begin @@ -45,7 +53,7 @@ begin begin with TDbf.Create(nil) do begin - FilePath := dbname; + FilePath := dbname; //specified in database.ini name= field TableName := 'fpdev_'+inttostr(n)+'.db'; FieldDefs.Add('ID',ftInteger); FieldDefs.Add('NAME',ftString,50); @@ -74,8 +82,8 @@ var i : integer; begin with TDbf.Create(nil) do begin - FilePath := dbname; - TableName := 'fpdev_field.db'; + FilePath := dbname; //specified in database.ini name= + TableName := FieldDatasetTableName; FieldDefs.Add('ID',ftInteger); FieldDefs.Add('FSTRING',ftString,10); FieldDefs.Add('FSMALLINT',ftSmallint); @@ -117,7 +125,7 @@ end; procedure TDBFDBConnector.DropFieldDataset; begin - DeleteFile(ExtractFilePath(dbname)+'fpdev_field.db'); + DeleteFile(ExtractFilePath(dbname)+FieldDatasetTableName); end; function TDBFDBConnector.InternalGetNDataset(n: integer): TDataset; @@ -125,7 +133,7 @@ begin Result := TDbf.Create(nil); with (result as TDbf) do begin - FilePath := dbname; + FilePath := dbname; //specified in database.ini name= field TableName := 'fpdev_'+inttostr(n)+'.db'; end; end; @@ -135,8 +143,8 @@ begin Result := TDbf.Create(nil); with (result as TDbf) do begin - FilePath := dbname; - TableName := 'fpdev_field.db'; + FilePath := dbname; //specified in database.ini name= field + TableName := FieldDatasetTableName; end; end; @@ -168,7 +176,7 @@ procedure TDbfTraceDataset.InternalInitFieldDefs; var i : integer; IntCalcFieldName : String; begin - // To fake a internal calculated field, set it's fielddef InternalCalcField + // To fake an internal calculated field, set its fielddef InternalCalcField // property to true, before the dataset is opened. // This procedure takes care of setting the automatically created fielddef's // InternalCalcField property to true. (works for only one field) diff --git a/packages/fcl-db/tests/dbtestframework_gui.lpr b/packages/fcl-db/tests/dbtestframework_gui.lpr index eacd62e4e7..a149496eb5 100644 --- a/packages/fcl-db/tests/dbtestframework_gui.lpr +++ b/packages/fcl-db/tests/dbtestframework_gui.lpr @@ -35,6 +35,7 @@ uses var DBSelectForm: TFormIniEditor; + TestRunForm: TGUITestRunner; begin Application.Initialize; DBSelectForm:=TFormIniEditor.Create(nil); @@ -47,7 +48,10 @@ begin finally DBSelectForm.Free; end; - Application.CreateForm(TGuiTestRunner, TestRunner); + // Manually run this form because autocreation could have loaded an old + // database.ini file (if the user changed it using DBSelectForm) + TestRunForm:=TGUITestRunner.Create(nil); + TestRunForm.Show; Application.Run; end. diff --git a/packages/fcl-db/tests/testdatasources.pas b/packages/fcl-db/tests/testdatasources.pas index 5a096097e3..4f99dc7dfb 100644 --- a/packages/fcl-db/tests/testdatasources.pas +++ b/packages/fcl-db/tests/testdatasources.pas @@ -365,7 +365,7 @@ begin open; AssertTrue(THackDataset(ds).InternalCalcFields); // If there are InternalCalcFields and 'normal' Calculated fields, only - // RefreshIntenralCalcFields is called + // RefreshInternalCalcFields is called AFld := FieldByName('id'); DataEvents := ''; THackDataset(ds).DataEvent(deFieldChange,PtrInt(AFld)); @@ -377,7 +377,7 @@ begin THackDataset(ds).DataEvent(deFieldChange,PtrInt(AFld)); AssertEquals('deFieldChange:NAME;',DataEvents); - // If the TDataset.State is dsSetKey then IntenralCalcFields shoudn't get called + // If the TDataset.State is dsSetKey then InternalCalcFields shoudn't get called THackDataset(ds).SetState(dsSetKey); AFld := FieldByName('id'); DataEvents := ''; diff --git a/packages/fcl-db/tests/toolsunit.pas b/packages/fcl-db/tests/toolsunit.pas index 2cccc823e6..517465496f 100644 --- a/packages/fcl-db/tests/toolsunit.pas +++ b/packages/fcl-db/tests/toolsunit.pas @@ -59,7 +59,8 @@ type Function GetNDataset(AChange : Boolean; n : integer) : TDataset; overload; Function GetFieldDataset : TDataSet; overload; Function GetFieldDataset(AChange : Boolean) : TDataSet; overload; - + + // Gets a dataset that tracks calculation of calculated fields etc. Function GetTraceDataset(AChange : Boolean) : TDataset; virtual; procedure StartTest;