瀏覽代碼

sqldb/dbtestframework fixes:
* slight cleanup dbftoolsunit
* Fix gui framework selecting old connector after selecting another.
* Cosmetic, spelling fixes.

git-svn-id: trunk@24090 -

reiniero 12 年之前
父節點
當前提交
9758f4fa6a

+ 7 - 6
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,...)
 

+ 4 - 3
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;

+ 1 - 1
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:

+ 16 - 8
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)

+ 5 - 1
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.
 

+ 2 - 2
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 := '';

+ 2 - 1
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;