+ added support for postgresql for test-framework

+ rewrote fieldtests (removed variant dependency)
 + added test for ftDateTime and unlimited VARCHAR
 + fieldnames are not case-sensitive for all RDMS

git-svn-id: trunk@3682 -
This commit is contained in:
joost 2006-05-26 11:28:20 +00:00
parent 530ab18c2a
commit 4924f7cfe0
4 changed files with 210 additions and 75 deletions

View File

@ -3,14 +3,10 @@
# type
# gives the type of the database-engine. Valid values are:
# * interbase
# * mysql40
# * mysql41
# * mysql50
# * odbc
# * mysql
# * postgresql
# * dbf
type=dbf
type=postgresql
# name
# gives the name of the database that should be used.
@ -18,7 +14,7 @@ type=dbf
# used. More information about how to create a dabatase can be find in the
# documentation of the database-engine.
name=/tmp
name=testdb
# user
# name is the name of a user which must have all rights on the selected
@ -27,13 +23,12 @@ name=/tmp
# How to set up users and their rights can be found in the database-engine
# documentation.
#user=sysdba
user=
# password
# password is the password of the provided user. If the password is incorrect,
# all or one of the test could fail.
#password=
#hostname=192.168.3.25
password=
hostname=

View File

@ -62,12 +62,12 @@ begin
AssertEquals(2,FieldCount);
AssertEquals('ID',fields[0].FieldName);
AssertEquals('ID',fields[0].DisplayName); // uitzoeken verschil displaylabel
AssertTrue(CompareText('ID',fields[0].FieldName)=0);
AssertTrue(CompareText('ID',fields[0].DisplayName)=0); // uitzoeken verschil displaylabel
AssertTrue('The datatype of the field ''ID'' is incorrect, it should be ftInteger',ftInteger=fields[0].DataType);
AssertEquals('NAME',fields[1].FieldName);
AssertEquals('NAME',fields[1].DisplayName);
AssertTrue(CompareText('NAME',fields[1].FieldName)=0);
AssertTrue(CompareText('NAME',fields[1].DisplayName)=0); // uitzoeken verschil displaylabel
AssertTrue(ftString=fields[1].DataType);
AssertEquals(1,fields[0].Value);

View File

@ -14,7 +14,8 @@ type
TTestFieldTypes= class(TTestCase)
private
procedure TestFldType(ADatatype: TFieldType; ADataSize: integer; ASQLTypeDecl: string; ATestValuesStr: array of string; ATestValues: array of variant);
procedure CreateTableWithFieldType(ADatatype : TFieldType; ASQLTypeDecl : string);
procedure TestFieldDeclaration(ADatatype: TFieldType; ADataSize: integer);
protected
procedure SetUp; override;
procedure TearDown; override;
@ -22,7 +23,9 @@ type
published
procedure TestInt;
procedure TestString;
procedure TestUnlVarChar;
procedure TestDate;
procedure TestDateTime; // bug 6925
end;
implementation
@ -33,27 +36,36 @@ procedure TTestFieldTypes.TestInt;
const
testValuesCount = 17;
testValuesInt : Array[0..testValuesCount-1] of integer = (-maxInt,-maxSmallint-1,-maxSmallint,-256,-255,-128,-127,-1,0,1,127,128,255,256,maxSmallint,maxSmallint+1,MaxInt);
testValues : Array[0..testValuesCount-1] of integer = (-maxInt,-maxSmallint-1,-maxSmallint,-256,-255,-128,-127,-1,0,1,127,128,255,256,maxSmallint,maxSmallint+1,MaxInt);
var
TestValues : array[0..testValuesCount-1] of variant;
TestValuesStr : array[0..testValuesCount-1] of string;
i : byte;
i : byte;
begin
CreateTableWithFieldType(ftInteger,'INT');
TestFieldDeclaration(ftInteger,4);
for i := 0 to testValuesCount-1 do
TSQLDBConnector(DBConnector).Connection.ExecuteDirect('insert into FPDEV2 (FT) values (' + inttostr(testValues[i]) + ')');
with TSQLDBConnector(DBConnector).Query do
begin
TestValues[i] := testValuesInt[i];
TestValuesStr[i] := inttostr(testValuesInt[i]);
Open;
for i := 0 to testValuesCount-1 do
begin
AssertEquals(testValues[i],fields[0].AsInteger);
Next;
end;
close;
end;
TestFldType(ftInteger,4,'INT',TestValuesStr,TestValues);
end;
procedure TTestFieldTypes.TestString;
const
testValuesCount = 15;
testValuesS : Array[0..testValuesCount-1] of string = (
testValuesCount = 19;
testValues : Array[0..testValuesCount-1] of string = (
'',
'a',
'ab',
'abc',
@ -68,72 +80,210 @@ const
'1234567890',
'_!@#$%^&*(',
')-;:/?.<>',
'~`|{}-='
'~`|{}- =', // note that there's no \ (backslash) since some db's uses that as escape-character
' WRaP ',
'wRaP ',
' wRAP'
);
var
TestValues : array[0..testValuesCount-1] of variant;
TestValuesStr : array[0..testValuesCount-1] of string;
i : byte;
begin
CreateTableWithFieldType(ftString,'VARCHAR(10)');
TestFieldDeclaration(ftString,11);
for i := 0 to testValuesCount-1 do
TSQLDBConnector(DBConnector).Connection.ExecuteDirect('insert into FPDEV2 (FT) values (''' + testValues[i] + ''')');
with TSQLDBConnector(DBConnector).Query do
begin
TestValuesStr[i] := '''' + testValuesS[i] + '''';
TestValues[i] := testValuesS[i];
Open;
for i := 0 to testValuesCount-1 do
begin
AssertEquals(testValues[i],fields[0].AsString);
Next;
end;
close;
end;
TestFldType(ftString,11,'VARCHAR(10)',TestValuesStr,TestValues);
end;
procedure TTestFieldTypes.TestUnlVarChar;
const
testValuesCount = 21;
testValues : Array[0..testValuesCount-1] of string = (
'',
'a',
'ab',
'abc',
'abcd',
'abcde',
'abcdef',
'abcdefg',
'abcdefgh',
'abcdefghi',
'abcdefghij',
'lMnOpQrStU',
'1234567890',
'_!@#$%^&*(',
')-;:/?.<>',
'~`|{}- =',
' WRaP ',
'wRaP ',
' wRAP',
'0123456789',
'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789 !@#$%^&*()_+-=][|}{;:,./<>?abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789 !@#$%^&*()_+-=][|}{;:,./<>?' + 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789 !@#$%^&*()_+-=][|}{;:,./<>?'
+ 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789 !@#$%^&*()_+-=][|}{;:,./<>?abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789 !@#$%^&*()_+-=][|}{;:,./<>?' + 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789 !@#$%^&*()_+-=][|}{;:,./<>?'
);
var
i : byte;
begin
CreateTableWithFieldType(ftString,'VARCHAR');
TestFieldDeclaration(ftString,dsMaxStringSize+1);
for i := 0 to testValuesCount-1 do
TSQLDBConnector(DBConnector).Connection.ExecuteDirect('insert into FPDEV2 (FT) values (''' + testValues[i] + ''')');
with TSQLDBConnector(DBConnector).Query do
begin
Open;
for i := 0 to testValuesCount-1 do
begin
AssertEquals(testValues[i],fields[0].AsString);
Next;
end;
close;
end;
end;
procedure TTestFieldTypes.TestDate;
const
testValuesCount = 14;
testValuesCount = 18;
testValues : Array[0..testValuesCount-1] of string = (
'2000-01-01',
'1999-12-31',
'2004-02-29',
'2004-03-01',
'1991-02-28',
'1991-03-01',
'2040-10-16',
'1977-09-29',
'1800-03-30',
'1650-05-10',
'1754-06-04',
'0904-04-12',
'0199-07-09',
'0001-01-01',
'1899-12-29',
'1899-12-30',
'1899-12-31',
'1900-01-01'
);
var
TestValues : array[0..testValuesCount-1] of variant;
TestValuesStr : array[0..testValuesCount-1] of string;
i : byte;
s : tdatetime;
begin
TestValues[0] := EncodeDate(2000,1,1);
TestValues[1] := EncodeDate(1999,12,31);
TestValues[2] := EncodeDate(2004,2,29);
TestValues[3] := EncodeDate(2004,3,1);
TestValues[4] := EncodeDate(1991,2,28);
TestValues[5] := EncodeDate(1991,3,1);
TestValues[6] := EncodeDate(2040,10,16);
TestValues[7] := EncodeDate(1977,9,29);
TestValues[8] := EncodeDate(1800,3,30);
TestValues[9] := EncodeDate(1650,5,1);
TestValues[10] := EncodeDate(1754,6,4);
TestValues[11] := EncodeDate(904,4,12);
TestValues[12] := EncodeDate(199,7,9);
TestValues[13] := EncodeDate(1,1,1);
CreateTableWithFieldType(ftDate,'DATE');
TestFieldDeclaration(ftDate,8);
for i := 0 to testValuesCount-1 do
TestValuesStr[i] := '''' + FormatDateTime('yyyy/mm/dd',testValues[i]) + '''';
TestFldType(ftDate,8,'DATE',TestValuesStr,TestValues);
TSQLDBConnector(DBConnector).Connection.ExecuteDirect('insert into FPDEV2 (FT) values (''' + testValues[i] + ''')');
// TSQLDBConnector(DBConnector).Transaction.CommitRetaining; // For debug-purposes
with TSQLDBConnector(DBConnector).Query do
begin
Open;
for i := 0 to testValuesCount-1 do
begin
AssertEquals(testValues[i],FormatDateTime('yyyy/mm/dd',fields[0].AsDateTime));
Next;
end;
close;
end;
end;
procedure TTestFieldTypes.TestFldType(ADatatype: TFieldType; ADataSize: integer;
ASQLTypeDecl: string; ATestValuesStr: array of string; ATestValues: array of variant);
procedure TTestFieldTypes.TestDateTime;
const
testValuesCount = 31;
testValues : Array[0..testValuesCount-1] of string = (
'2000-01-01',
'1999-12-31',
'2004-02-29',
'2004-03-01',
'1991-02-28',
'1991-03-01',
'2040-10-16',
'1977-09-29',
'1800-03-30',
'1650-05-10',
'1754-06-04',
'0904-04-12',
'0199-07-09',
'0001-01-01',
'1899-12-29',
'1899-12-30',
'1899-12-31',
'1900-01-01',
'1899-12-30 18:00:51',
'1899-12-30 04:00:51',
'1899-12-29 04:00:51',
'1899-12-29 18:00:51',
'2000-01-01 10:00:00',
'2000-01-01 23:59:59',
'2100-01-01 01:01:01',
'1400-02-03 12:21:53',
'1333-02-03 21:44:21',
'1994-03-06 11:54:30',
'1903-04-02 01:04:02',
'1815-09-24 03:47:22',
'0354-11-20 21:25:15'
);
var
i : byte;
testValuesCount : integer;
s : string;
i : byte;
begin
testValuesCount := length(ATestValues);
CreateTableWithFieldType(ftDateTime,'TIMESTAMP');
TestFieldDeclaration(ftDateTime,8);
for i := 0 to testValuesCount-1 do
TSQLDBConnector(DBConnector).Connection.ExecuteDirect('insert into FPDEV2 (FT) values (''' + testValues[i] + ''')');
with TSQLDBConnector(DBConnector).Query do
begin
Open;
for i := 0 to testValuesCount-1 do
begin
if length(testValues[i]) < 12 then
AssertEquals(testValues[i],FormatDateTime('yyyy/mm/dd',fields[0].AsDateTime))
else
AssertEquals(testValues[i],FormatDateTime('yyyy/mm/dd hh:mm:ss',fields[0].AsDateTime));
Next;
end;
close;
end;
end;
procedure TTestFieldTypes.CreateTableWithFieldType(ADatatype: TFieldType;
ASQLTypeDecl: string);
begin
TSQLDBConnector(DBConnector).Connection.ExecuteDirect('create table FPDEV2 (FT ' +ASQLTypeDecl+ ')');
// Firebird/Interbase need a commit after a DDL statement. Not necessary for the other connections
TSQLDBConnector(DBConnector).Transaction.CommitRetaining;
end;
procedure TTestFieldTypes.TestFieldDeclaration(ADatatype: TFieldType;
ADataSize: integer);
begin
with TSQLDBConnector(DBConnector).Query do
begin
SQL.Clear;
@ -141,23 +291,11 @@ begin
Open;
AssertEquals(1,FieldCount);
AssertEquals('FT',fields[0].FieldName);
AssertTrue(CompareText('FT',fields[0].FieldName)=0);
AssertEquals(ADataSize,fields[0].DataSize);
AssertTrue(ADatatype=fields[0].DataType);
Close;
for i := 0 to testValuesCount-1 do
TSQLDBConnector(DBConnector).Connection.ExecuteDirect('insert into FPDEV2 (FT) values (' + AtestValuesStr[i] + ')');
// TSQLDBConnector(DBConnector).Transaction.CommitRetaining; // For debug-purposes
Open;
for i := 0 to testValuesCount-1 do
begin
AssertEquals(string(AtestValues[i]),fields[0].Value);
Next;
end;
close;
end;
TSQLDBConnector(DBConnector).Transaction.Rollback;
end;
procedure TTestFieldTypes.SetUp;
@ -167,17 +305,19 @@ end;
procedure TTestFieldTypes.TearDown;
begin
if assigned(DBConnector) then
TSQLDBConnector(DBConnector).Transaction.Rollback;
FreeAndNil(DBConnector);
end;
procedure TTestFieldTypes.RunTest;
begin
if dbtype = 'interbase' then
if (dbtype = 'interbase') or
(dbtype = 'postgresql') then
inherited RunTest;
end;
initialization
RegisterTest(TTestFieldTypes);
RegisterTest(TTestFieldTypes);
end.

View File

@ -92,7 +92,7 @@ begin
ReadIniFile;
if (1 <> 1) then begin end
{$IFDEF SQLDB_AVAILABLE}
else if dbtype = 'interbase' then DBConnector := TSQLDBConnector.Create
else if (dbtype = 'interbase') or (dbtype = 'postgresql') then DBConnector := TSQLDBConnector.Create
{$ENDIF}
{$IFDEF DBF_AVAILABLE}
else if dbtype = 'dbf' then DBConnector := TDBFDBConnector.Create