fpc/packages/fcl-db/tests
2023-07-24 16:32:02 +02:00
..
.gitignore * Ignore output programs 2022-05-01 16:22:55 +02:00
bufdatasettoolsunit.pas * PChar -> PansiChar 2023-07-15 18:22:41 +02:00
database.ini.txt
dbftoolsunit.pas * PChar -> PansiChar 2023-07-15 18:22:41 +02:00
dbguitestrunner.pas
dbtestframework_gui.lpi
dbtestframework_gui.lpr * Additional tests for sqlite3dataset by Luis Americo (bug ID 323247) 2019-09-08 10:31:05 +00:00
dbtestframework.lpi * PChar -> PansiChar 2023-07-15 18:22:41 +02:00
dbtestframework.pas * Fix bug ID #31385 2019-09-11 07:40:44 +00:00
inieditor.lfm
inieditor.pas
Makefile * Regenerate makefiles with subtarget support 2023-07-24 16:32:02 +02:00
Makefile.fpc
memdstoolsunit.pas * Patch from Laco to add TSingleField 2022-02-14 09:15:43 +01:00
README.txt
reruntest.sh
sdfdstoolsunit.pas
sqldbtoolsunit.pas * PChar -> PansiChar 2023-07-15 18:22:41 +02:00
sqlite3dstoolsunit.pas * Additional tests for sqlite3dataset by Luis Americo (bug ID 323247) 2019-09-08 10:31:05 +00:00
tccsvdataset.pp * Make sure open/close use same options in CSV close/open writing 2019-12-05 16:16:08 +00:00
tcgensql.pas sql parser: unify identifier path code 2020-08-14 17:46:38 +00:00
tcparser.pas * PChar -> PAnsiChar 2023-07-15 18:22:41 +02:00
tcsdfdata.pp
tcsqlscanner.pas * PChar -> PAnsiChar 2023-07-15 18:22:41 +02:00
test-list.txt
test.json
testbasics.pas
testbufdatasetstreams.pas * Fix name array 2019-12-05 14:02:03 +00:00
testdatasources.pas * PChar -> PansiChar 2023-07-15 18:22:41 +02:00
testdbbasics.pas * PChar -> PansiChar 2023-07-15 18:22:41 +02:00
testdbexport.pas * PChar -> PansiChar 2023-07-15 18:22:41 +02:00
testdddiff.pp
testfieldtypes.pas * PChar -> PansiChar 2023-07-15 18:22:41 +02:00
testjsondataset.lpi * Lazarus project file for json test 2019-09-19 17:14:49 +00:00
testjsondataset.pp * Fix memleaks (bug ID 36408) 2019-12-08 20:05:14 +00:00
testleaks.sh
testspecifictbufdataset.pas * Added test for bug ID #36086 (lookup on empty dataset) 2019-09-19 07:40:26 +00:00
testspecifictdbf.pas
testspecifictmemdataset.pas * Fix bug ID #31385 2019-09-11 07:40:44 +00:00
testspecifictsqlite3dataset.pp * Additional tests for sqlite3dataset by Luis Americo (bug ID 323247) 2019-09-08 10:31:05 +00:00
testsqldb.pas * Patch from Luiz Americo to implement SQL_NULL params on firebird (bug ID 37646) 2020-09-03 09:40:44 +00:00
testsqlfiles.lpi
testsqlfiles.lpr
testsqlscanner_gui.lpi
testsqlscanner_gui.lpr
testsqlscanner.lpi * PChar -> PAnsiChar 2023-07-15 18:22:41 +02:00
testsqlscanner.lpr * PChar -> PAnsiChar 2023-07-15 18:22:41 +02:00
testsqlscript.pas * PChar -> PansiChar 2023-07-15 18:22:41 +02:00
toolsunit.pas * PChar -> PansiChar 2023-07-15 18:22:41 +02:00

This directory contains a framework to test several TDataset descendents.
A lot of these tests are only applicable for SQL databases, but there are several tests that also apply to other objects, such as TBufDataset.

The framework is based on the fpcunit unit test system. The tests can be
executed using any fpcunit testrunner. For example the console and graphical
fpcunit test runners from Lazarus.
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. 
Additionally, a GUI Lazarus unit (dbtestframework_gui.lpr) is included for convenience.

DBTestframework architecture
============================
To test a TDataset descendent, a 'connector' is needed to test the database.
To add a new connector, create a new *toolsunit.pas file, then add it to 
the uses section in 'dbtestframework.pas' and 'dbtestframework_gui.lpr'.
Several connectors are available in the '*toolsunit.pas' files.

The connector must inherit from TDBConnector in toolsunit.pas.
The connector implements two different kinds of datasets: 
- a dataset with as many different kinds of fields as possible (see the *FieldDataSets subroutines).
- a dataset with only a few fields (ID and NAME), but a lot (well, MaxDataset) of different records (see the *NDataSets subroutines)

CreateNDatasets and CreateFieldDataset should be implemented to set up data stores (e.g. database tables) and fill these stores with test data for the respective datasets.
The corresponding Drop*Dataset procedures must drop the tables/delete the data.

GetNDataset and GetFieldsDataset should return the relevant dataset in closed state so the tests can open them and work with them.
They call InternalGetNDataset and InternalGetFieldDataset which should be implemented in all descendents and returns the relevant dataset, closed, with all data.

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.

Tests
=====
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)
  ...
initialization  
  if uppercase(dbconnectorname)='BUFDATASET' then
    begin
    RegisterTestDecorator(TDBBasicsTestSetup, TTestSpecificTBufDataset);
    end;
	
In your individual tests, you can indicate you want to run tests only in certain cases, e.g. for certain SQLDB databases:
  if not(SQLConnType in [interbase]) then Ignore(STestNotApplicable);
  
Setting up your database
========================
Some tests are file based (e.g. those for bufdataset); others by their nature need databases (e.g. a Firebird SQLDB test).
File-based tests will generally write to the current/test directory, a subdirectory or a temp file.

For SQLDB database servers, please make sure you have a username/password and a database set up that the test suite can use and abuse.
The database can be empty: the test suite will create and delete tables etc. in this database as needed.

Specifying databases, connector names
=====================================
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 a template/example.

The connector names to be used are derived from the connector classes.

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 parameters such as
connectorparams=postgresql (which specify db type) are needed
The parameters used depend on the connector type (sql,...)

If you specify the wrong (or no) name (or don't have database.ini), you will get an exception in your test runner:
Unknown db connector specified

Joost van der Sluis (30-12-2006), 
amended by Reinier Olislagers (2012)