mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-08-17 17:49:13 +02:00
sqldb/dbtestframework fixes:
* slight cleanup dbftoolsunit * Fix gui framework selecting old connector after selecting another. * Cosmetic, spelling fixes. git-svn-id: trunk@24090 -
This commit is contained in:
parent
ad455d05b1
commit
9758f4fa6a
@ -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.
|
test runner and all tests will get registered and executed.
|
||||||
|
|
||||||
A simple test runner (dbtestframework.pas) which generates XML output is
|
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
|
DBTestframework architecture
|
||||||
============================
|
============================
|
||||||
@ -31,11 +32,11 @@ They call InternalGetNDataset and InternalGetFieldDataset which should be implem
|
|||||||
Toolsunit.pas defines some variables for use, e.g.
|
Toolsunit.pas defines some variables for use, e.g.
|
||||||
- testValuesCount is the number of records/test values in the FieldDataset dataset
|
- testValuesCount is the number of records/test values in the FieldDataset dataset
|
||||||
- MaxDataset is the same for NDataset.
|
- 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
|
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:
|
E.g. this example to only run for Bufdataset tests:
|
||||||
TTestSpecificTBufDataset = class(TTestCase)
|
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
|
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
|
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.
|
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
|
- it has this class definition
|
||||||
TSQLDBConnector = class(TDBConnector)
|
TSQLDBConnector = class(TDBConnector)
|
||||||
- its name in database.ini is sqldb
|
- 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
|
connectorparams=postgresql (which specify db type) are needed
|
||||||
The parameters used depend on the connector type (sql,...)
|
The parameters used depend on the connector type (sql,...)
|
||||||
|
|
||||||
|
@ -1,10 +1,11 @@
|
|||||||
unit BufDatasetToolsUnit;
|
unit BufDatasetToolsUnit;
|
||||||
|
|
||||||
{ Sets up bufdataset for testing.
|
{ 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.
|
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+}
|
{$mode objfpc}{$H+}
|
||||||
@ -64,7 +65,7 @@ end;
|
|||||||
|
|
||||||
procedure TbufdatasetDBConnector.CreateNDatasets;
|
procedure TbufdatasetDBConnector.CreateNDatasets;
|
||||||
begin
|
begin
|
||||||
// All datasets are created in InternalGet*Dataset
|
// All datasets are created in InternalGet*Dataset
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TbufdatasetDBConnector.CreateFieldDataset;
|
procedure TbufdatasetDBConnector.CreateFieldDataset;
|
||||||
|
@ -161,7 +161,7 @@ hostname=127.0.0.1
|
|||||||
[dbf]
|
[dbf]
|
||||||
connector=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
|
name=/tmp
|
||||||
|
|
||||||
; MemDS in memory dataset:
|
; MemDS in memory dataset:
|
||||||
|
@ -1,5 +1,10 @@
|
|||||||
unit DBFToolsUnit;
|
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}
|
{$IFDEF FPC}
|
||||||
{$mode objfpc}{$H+}
|
{$mode objfpc}{$H+}
|
||||||
{$ENDIF}
|
{$ENDIF}
|
||||||
@ -38,6 +43,9 @@ type
|
|||||||
|
|
||||||
implementation
|
implementation
|
||||||
|
|
||||||
|
const
|
||||||
|
FieldDatasetTableName='fpdev_field.db';
|
||||||
|
|
||||||
procedure TDBFDBConnector.CreateNDatasets;
|
procedure TDBFDBConnector.CreateNDatasets;
|
||||||
var countID,n : integer;
|
var countID,n : integer;
|
||||||
begin
|
begin
|
||||||
@ -45,7 +53,7 @@ begin
|
|||||||
begin
|
begin
|
||||||
with TDbf.Create(nil) do
|
with TDbf.Create(nil) do
|
||||||
begin
|
begin
|
||||||
FilePath := dbname;
|
FilePath := dbname; //specified in database.ini name= field
|
||||||
TableName := 'fpdev_'+inttostr(n)+'.db';
|
TableName := 'fpdev_'+inttostr(n)+'.db';
|
||||||
FieldDefs.Add('ID',ftInteger);
|
FieldDefs.Add('ID',ftInteger);
|
||||||
FieldDefs.Add('NAME',ftString,50);
|
FieldDefs.Add('NAME',ftString,50);
|
||||||
@ -74,8 +82,8 @@ var i : integer;
|
|||||||
begin
|
begin
|
||||||
with TDbf.Create(nil) do
|
with TDbf.Create(nil) do
|
||||||
begin
|
begin
|
||||||
FilePath := dbname;
|
FilePath := dbname; //specified in database.ini name=
|
||||||
TableName := 'fpdev_field.db';
|
TableName := FieldDatasetTableName;
|
||||||
FieldDefs.Add('ID',ftInteger);
|
FieldDefs.Add('ID',ftInteger);
|
||||||
FieldDefs.Add('FSTRING',ftString,10);
|
FieldDefs.Add('FSTRING',ftString,10);
|
||||||
FieldDefs.Add('FSMALLINT',ftSmallint);
|
FieldDefs.Add('FSMALLINT',ftSmallint);
|
||||||
@ -117,7 +125,7 @@ end;
|
|||||||
|
|
||||||
procedure TDBFDBConnector.DropFieldDataset;
|
procedure TDBFDBConnector.DropFieldDataset;
|
||||||
begin
|
begin
|
||||||
DeleteFile(ExtractFilePath(dbname)+'fpdev_field.db');
|
DeleteFile(ExtractFilePath(dbname)+FieldDatasetTableName);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TDBFDBConnector.InternalGetNDataset(n: integer): TDataset;
|
function TDBFDBConnector.InternalGetNDataset(n: integer): TDataset;
|
||||||
@ -125,7 +133,7 @@ begin
|
|||||||
Result := TDbf.Create(nil);
|
Result := TDbf.Create(nil);
|
||||||
with (result as TDbf) do
|
with (result as TDbf) do
|
||||||
begin
|
begin
|
||||||
FilePath := dbname;
|
FilePath := dbname; //specified in database.ini name= field
|
||||||
TableName := 'fpdev_'+inttostr(n)+'.db';
|
TableName := 'fpdev_'+inttostr(n)+'.db';
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
@ -135,8 +143,8 @@ begin
|
|||||||
Result := TDbf.Create(nil);
|
Result := TDbf.Create(nil);
|
||||||
with (result as TDbf) do
|
with (result as TDbf) do
|
||||||
begin
|
begin
|
||||||
FilePath := dbname;
|
FilePath := dbname; //specified in database.ini name= field
|
||||||
TableName := 'fpdev_field.db';
|
TableName := FieldDatasetTableName;
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@ -168,7 +176,7 @@ procedure TDbfTraceDataset.InternalInitFieldDefs;
|
|||||||
var i : integer;
|
var i : integer;
|
||||||
IntCalcFieldName : String;
|
IntCalcFieldName : String;
|
||||||
begin
|
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.
|
// property to true, before the dataset is opened.
|
||||||
// This procedure takes care of setting the automatically created fielddef's
|
// This procedure takes care of setting the automatically created fielddef's
|
||||||
// InternalCalcField property to true. (works for only one field)
|
// InternalCalcField property to true. (works for only one field)
|
||||||
|
@ -35,6 +35,7 @@ uses
|
|||||||
|
|
||||||
var
|
var
|
||||||
DBSelectForm: TFormIniEditor;
|
DBSelectForm: TFormIniEditor;
|
||||||
|
TestRunForm: TGUITestRunner;
|
||||||
begin
|
begin
|
||||||
Application.Initialize;
|
Application.Initialize;
|
||||||
DBSelectForm:=TFormIniEditor.Create(nil);
|
DBSelectForm:=TFormIniEditor.Create(nil);
|
||||||
@ -47,7 +48,10 @@ begin
|
|||||||
finally
|
finally
|
||||||
DBSelectForm.Free;
|
DBSelectForm.Free;
|
||||||
end;
|
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;
|
Application.Run;
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
@ -365,7 +365,7 @@ begin
|
|||||||
open;
|
open;
|
||||||
AssertTrue(THackDataset(ds).InternalCalcFields);
|
AssertTrue(THackDataset(ds).InternalCalcFields);
|
||||||
// If there are InternalCalcFields and 'normal' Calculated fields, only
|
// If there are InternalCalcFields and 'normal' Calculated fields, only
|
||||||
// RefreshIntenralCalcFields is called
|
// RefreshInternalCalcFields is called
|
||||||
AFld := FieldByName('id');
|
AFld := FieldByName('id');
|
||||||
DataEvents := '';
|
DataEvents := '';
|
||||||
THackDataset(ds).DataEvent(deFieldChange,PtrInt(AFld));
|
THackDataset(ds).DataEvent(deFieldChange,PtrInt(AFld));
|
||||||
@ -377,7 +377,7 @@ begin
|
|||||||
THackDataset(ds).DataEvent(deFieldChange,PtrInt(AFld));
|
THackDataset(ds).DataEvent(deFieldChange,PtrInt(AFld));
|
||||||
AssertEquals('deFieldChange:NAME;',DataEvents);
|
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);
|
THackDataset(ds).SetState(dsSetKey);
|
||||||
AFld := FieldByName('id');
|
AFld := FieldByName('id');
|
||||||
DataEvents := '';
|
DataEvents := '';
|
||||||
|
@ -59,7 +59,8 @@ type
|
|||||||
Function GetNDataset(AChange : Boolean; n : integer) : TDataset; overload;
|
Function GetNDataset(AChange : Boolean; n : integer) : TDataset; overload;
|
||||||
Function GetFieldDataset : TDataSet; overload;
|
Function GetFieldDataset : TDataSet; overload;
|
||||||
Function GetFieldDataset(AChange : Boolean) : TDataSet; overload;
|
Function GetFieldDataset(AChange : Boolean) : TDataSet; overload;
|
||||||
|
|
||||||
|
// Gets a dataset that tracks calculation of calculated fields etc.
|
||||||
Function GetTraceDataset(AChange : Boolean) : TDataset; virtual;
|
Function GetTraceDataset(AChange : Boolean) : TDataset; virtual;
|
||||||
|
|
||||||
procedure StartTest;
|
procedure StartTest;
|
||||||
|
Loading…
Reference in New Issue
Block a user