From 9f2e076cb31c3085e190d102032974d82ba40e01 Mon Sep 17 00:00:00 2001 From: joost Date: Sun, 23 Nov 2008 15:29:13 +0000 Subject: [PATCH] * Added two fcl-db tests to the general testsuite git-svn-id: trunk@12216 - --- .gitattributes | 6 ++ tests/Makefile | 4 +- tests/Makefile.fpc | 2 +- tests/test/packages/fcl-db/assertions.pas | 32 ++++++++ tests/test/packages/fcl-db/database.ini | 90 +++++++++++++++++++++ tests/test/packages/fcl-db/dbftoolsunit.pas | 1 + tests/test/packages/fcl-db/tdb1.pp | 44 ++++++++++ tests/test/packages/fcl-db/tdb2.pp | 47 +++++++++++ tests/test/packages/fcl-db/toolsunit.pas | 1 + 9 files changed, 224 insertions(+), 3 deletions(-) create mode 100644 tests/test/packages/fcl-db/assertions.pas create mode 100644 tests/test/packages/fcl-db/database.ini create mode 100644 tests/test/packages/fcl-db/dbftoolsunit.pas create mode 100644 tests/test/packages/fcl-db/tdb1.pp create mode 100644 tests/test/packages/fcl-db/tdb2.pp create mode 100644 tests/test/packages/fcl-db/toolsunit.pas diff --git a/.gitattributes b/.gitattributes index 3090750b01..a110c6fb35 100644 --- a/.gitattributes +++ b/.gitattributes @@ -7586,6 +7586,12 @@ tests/test/opt/treg3.pp svneol=native#text/plain tests/test/opt/treg4.pp svneol=native#text/plain tests/test/opt/tretopt.pp svneol=native#text/plain tests/test/opt/tspace.pp svneol=native#text/plain +tests/test/packages/fcl-db/assertions.pas svneol=native#text/plain +tests/test/packages/fcl-db/database.ini svneol=native#text/plain +tests/test/packages/fcl-db/dbftoolsunit.pas svneol=native#text/plain +tests/test/packages/fcl-db/tdb1.pp svneol=native#text/plain +tests/test/packages/fcl-db/tdb2.pp svneol=native#text/plain +tests/test/packages/fcl-db/toolsunit.pas svneol=native#text/plain tests/test/packages/fcl-registry/tregistry1.pp svneol=native#text/plain tests/test/packages/hash/tmdtest.pp svneol=native#text/plain tests/test/packages/webtbs/tw10045.pp svneol=native#text/plain diff --git a/tests/Makefile b/tests/Makefile index 69d547176d..1ccdc7857d 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -1,5 +1,5 @@ # -# Don't edit, this file is generated by FPCMake Version 2.0.0 [2008/09/28] +# Don't edit, this file is generated by FPCMake Version 2.0.0 [2008/11/23] # default: allexectests MAKEFILETARGETS=i386-linux i386-go32v2 i386-win32 i386-os2 i386-freebsd i386-beos i386-haiku i386-netbsd i386-solaris i386-qnx i386-netware i386-openbsd i386-wdosx i386-darwin i386-emx i386-watcom i386-netwlibc i386-wince i386-embedded i386-symbian m68k-linux m68k-freebsd m68k-netbsd m68k-amiga m68k-atari m68k-openbsd m68k-palmos m68k-embedded powerpc-linux powerpc-netbsd powerpc-amiga powerpc-macos powerpc-darwin powerpc-morphos powerpc-embedded sparc-linux sparc-netbsd sparc-solaris sparc-embedded x86_64-linux x86_64-freebsd x86_64-darwin x86_64-win64 x86_64-embedded arm-linux arm-palmos arm-darwin arm-wince arm-gba arm-nds arm-embedded arm-symbian powerpc64-linux powerpc64-darwin powerpc64-embedded avr-embedded armeb-linux armeb-embedded @@ -1443,7 +1443,7 @@ ifndef LOG export LOG:=$(TEST_OUTPUTDIR)/log endif TESTSUBDIRS=cg cg/variants cg/cdecl opt units/system units/dos units/crt units/objects units/strings units/sysutils units/math units/sharemem -TESTPACKAGESUBDIRS=cg packages/win-base packages/webtbs packages/hash packages/fcl-registry packages/fcl-process packages/zlib +TESTPACKAGESUBDIRS=cg packages/win-base packages/webtbs packages/hash packages/fcl-registry packages/fcl-process packages/zlib packages/fcl-db ifdef QUICKTEST export QUICKTEST else diff --git a/tests/Makefile.fpc b/tests/Makefile.fpc index 00b39697f3..262400b4ef 100644 --- a/tests/Makefile.fpc +++ b/tests/Makefile.fpc @@ -120,7 +120,7 @@ endif # Subdirs available in the test subdir TESTSUBDIRS=cg cg/variants cg/cdecl opt units/system units/dos units/crt units/objects units/strings units/sysutils units/math units/sharemem -TESTPACKAGESUBDIRS=cg packages/win-base packages/webtbs packages/hash packages/fcl-registry packages/fcl-process packages/zlib +TESTPACKAGESUBDIRS=cg packages/win-base packages/webtbs packages/hash packages/fcl-registry packages/fcl-process packages/zlib packages/fcl-db ifdef QUICKTEST export QUICKTEST diff --git a/tests/test/packages/fcl-db/assertions.pas b/tests/test/packages/fcl-db/assertions.pas new file mode 100644 index 0000000000..23af76e2aa --- /dev/null +++ b/tests/test/packages/fcl-db/assertions.pas @@ -0,0 +1,32 @@ +unit Assertions; + +{$mode objfpc}{$H+} + +interface + +uses + Classes, SysUtils; + +procedure AssertTrue(v1 : boolean); +procedure AssertEquals(v1,v2 : string); overload; +procedure AssertEquals(v1,v2 : integer); overload; + +implementation + +procedure AssertTrue(v1: boolean); +begin + if not v1 then halt(1); +end; + +procedure AssertEquals(v1, v2: string); +begin + AssertTrue(v1=v2); +end; + +procedure AssertEquals(v1, v2: integer); +begin + AssertTrue(v1=v2); +end; + +end. + diff --git a/tests/test/packages/fcl-db/database.ini b/tests/test/packages/fcl-db/database.ini new file mode 100644 index 0000000000..78448ba19a --- /dev/null +++ b/tests/test/packages/fcl-db/database.ini @@ -0,0 +1,90 @@ +; This file contains several sections, one for each database-type. Select here +; which section has to be used currently. +[Database] +type=dbf + +; These sections are for the several SQLDB-types of databases: +[postgresql] + +; The connector specifies the DB-component that has to be used. The 'sql' +; connector tests the SQLDB components +connector=sql + +; Here you can give some parameters, which are specific for each connector. The +; SQL connector uses this parameter to specify the connection that should be +; used; +connectorparams=postgresql + +; The name of the database. The database could be empty. You only need read and +; write rights. +name=testdb + +; user to log in with +user= + +; password to log in with +password= + +; hostname of the database-server +hostname=127.0.0.1 + +[mysql40] +connector=sql +connectorparams=mysql40 +name=testdb +user=root +password= +hostname=127.0.0.1 + +[mysql41] +connector=sql +connectorparams=mysql41 +name=testdb +user=root +password= +hostname=127.0.0.1 + +[mysql50] +connector=sql +connectorparams=mysql50 +name=testdb +user=root +password= +hostname=127.0.0.1 + +[oracle] +connector=sql +connectorparams=oracle +name=xe +user=system +password= +hostname=127.0.0.1 + +[interbase] +connector=sql +connectorparams=interbase +name=/opt/firebird/data/testdb.fdb +user=sysdba +password= +hostname=localhost + +[odbc] +connector=sql +connectorparams=odbc +name=testdb +user=root +password= +hostname=127.0.0.1 + + +; This section is for a connector for TDbf: +[dbf] +connector=dbf + +; Give here the path where the *.dbf file can be generated +name=. + +; This section is for a connector for MemDS: +[memds] +connector=memds + diff --git a/tests/test/packages/fcl-db/dbftoolsunit.pas b/tests/test/packages/fcl-db/dbftoolsunit.pas new file mode 100644 index 0000000000..c06722788c --- /dev/null +++ b/tests/test/packages/fcl-db/dbftoolsunit.pas @@ -0,0 +1 @@ +{$i ../../../../packages/fcl-db/tests/dbftoolsunit.pas} diff --git a/tests/test/packages/fcl-db/tdb1.pp b/tests/test/packages/fcl-db/tdb1.pp new file mode 100644 index 0000000000..3fb5b6696a --- /dev/null +++ b/tests/test/packages/fcl-db/tdb1.pp @@ -0,0 +1,44 @@ +program TTestDBBasics_TestGetFieldValues; + +{$mode objfpc}{$H+} + +uses + Classes, SysUtils, + Assertions, + ToolsUnit, + dbftoolsunit, + db; + +var AVar : Variant; + PassException : boolean; + +begin + InitialiseDBConnector; + with DBConnector.GetNDataset(true,14) do + begin + open; + AVar:=FieldValues['id']; + AssertEquals(AVar,1); + + AVar:=FieldValues['name']; + AssertEquals(AVar,'TestName1'); + + AVar:=FieldValues['id;name']; + AssertEquals(AVar[0],1); + AssertEquals(AVar[1],'TestName1'); + + AVar:=FieldValues['name;id;']; + AssertEquals(AVar[1],1); + AssertEquals(AVar[0],'TestName1'); + + PassException:=false; + try + AVar:=FieldValues['name;id;fake']; + except + on E: EDatabaseError do PassException := True; + end; + AssertTrue(PassException); + + end; +end. + diff --git a/tests/test/packages/fcl-db/tdb2.pp b/tests/test/packages/fcl-db/tdb2.pp new file mode 100644 index 0000000000..9556f68f95 --- /dev/null +++ b/tests/test/packages/fcl-db/tdb2.pp @@ -0,0 +1,47 @@ +program TTestDBBasics_TestSetFieldValues; + +{$mode objfpc}{$H+} + +uses + Classes, SysUtils, + Assertions, + ToolsUnit, + dbftoolsunit, + variants, + db; + +var PassException : boolean; + +begin + InitialiseDBConnector; + with DBConnector.GetNDataset(true,11) do + begin + open; + first; + edit; + FieldValues['id']:=5; + post; + AssertEquals('TestName1',FieldByName('name').AsString); + AssertEquals(5,FieldByName('id').AsInteger); + edit; + FieldValues['name']:='FieldValuesTestName'; + post; + AssertEquals('FieldValuesTestName',FieldByName('name').AsString); + AssertEquals(5,FieldByName('id').AsInteger); + edit; + FieldValues['id;name']:= VarArrayOf([243,'ValuesTestName']); + post; + AssertEquals('ValuesTestName',FieldByName('name').AsString); + AssertEquals(243,FieldByName('id').AsInteger); + + PassException:=false; + try + edit; + FieldValues['id;name;fake']:= VarArrayOf([243,'ValuesTestName',4]); + except + on E: EDatabaseError do PassException := True; + end; + post; + AssertTrue(PassException); + end; +end. diff --git a/tests/test/packages/fcl-db/toolsunit.pas b/tests/test/packages/fcl-db/toolsunit.pas new file mode 100644 index 0000000000..156f20b54d --- /dev/null +++ b/tests/test/packages/fcl-db/toolsunit.pas @@ -0,0 +1 @@ +{$i ../../../../packages/fcl-db/tests/toolsunit.pas}