Browse Source

fcl-db: tests: Adjust tests to take into account connection charset and field codepage when testing Size and DataSize

git-svn-id: trunk@39003 -
lacak 7 years ago
parent
commit
1edf2d3cd0

+ 15 - 36
packages/fcl-db/tests/database.ini.txt

@@ -35,6 +35,9 @@ password=masterkey
 ; of the database server
 ; of the database server
 hostname=localhost
 hostname=localhost
 
 
+; connection character set
+charset=
+
 ; SQL command log file (for sqldb databases)
 ; SQL command log file (for sqldb databases)
 ; will be appended to each run
 ; will be appended to each run
 ; uncomment to use
 ; uncomment to use
@@ -57,42 +60,7 @@ name=fbembedtest.fdb
 user=sysdba
 user=sysdba
 password=masterkey
 password=masterkey
 hostname=
 hostname=
-
-[mysql40]
-; MySQL 4.0 database:
-connector=sql
-connectorparams=mysql40
-name=testdb
-user=root
-password=
-hostname=127.0.0.1
-
-[mysql41]
-; MySQL 4.1 database:
-connector=sql
-connectorparams=mysql41
-name=testdb
-user=root
-password=
-hostname=127.0.0.1
-
-[mysql50]
-; MySQL 5.0 database:
-connector=sql
-connectorparams=mysql50
-name=testdb
-user=root
-password=
-hostname=127.0.0.1
-
-[mysql51]
-; MySQL 5.1 database:
-connector=sql
-connectorparams=mysql51
-name=testdb
-user=root
-password=
-hostname=127.0.0.1
+charset=utf8
 
 
 [mysql55]
 [mysql55]
 ; MySQL 5.5 database:
 ; MySQL 5.5 database:
@@ -112,6 +80,16 @@ user=root
 password=
 password=
 hostname=127.0.0.1
 hostname=127.0.0.1
 
 
+[mysql57]
+; MySQL 5.7 database:
+connector=sql
+connectorparams=mysql57
+name=testdb
+user=root
+password=
+hostname=127.0.0.1
+charset=utf8mb4
+
 [mssql]
 [mssql]
 ; MS SQL Server database:
 ; MS SQL Server database:
 connector=sql
 connector=sql
@@ -161,6 +139,7 @@ hostname=127.0.0.1
 connector=sql
 connector=sql
 connectorparams=sqlite3
 connectorparams=sqlite3
 name=test.db
 name=test.db
+charset=utf-8
 
 
 [sybase]
 [sybase]
 ; Sybase ASE database
 ; Sybase ASE database

+ 2 - 2
packages/fcl-db/tests/testdbbasics.pas

@@ -2684,7 +2684,7 @@ var i          : byte;
     Fld        : TField;
     Fld        : TField;
 
 
 begin
 begin
-  TestFieldDefinition(ftString,11,ds,Fld);
+  TestFieldDefinition(ftString, 10*DBConnector.CharSize+1, ds, Fld);
 
 
   for i := 0 to testValuesCount-1 do
   for i := 0 to testValuesCount-1 do
     begin
     begin
@@ -2872,7 +2872,7 @@ var i          : byte;
     Fld        : TField;
     Fld        : TField;
 
 
 begin
 begin
-  TestFieldDefinition(ftFixedChar,11,ds,Fld);
+  TestFieldDefinition(ftFixedChar, 10*DBConnector.CharSize+1, ds, Fld);
 
 
   for i := 0 to testValuesCount-1 do
   for i := 0 to testValuesCount-1 do
     begin
     begin

+ 2 - 2
packages/fcl-db/tests/testfieldtypes.pas

@@ -438,7 +438,7 @@ var
 
 
 begin
 begin
   CreateTableWithFieldType(ftString,'VARCHAR(10)');
   CreateTableWithFieldType(ftString,'VARCHAR(10)');
-  TestFieldDeclaration(ftString,11);
+  TestFieldDeclaration(ftString,10*DBConnector.CharSize+1);
 
 
   for i := 0 to testValuesCount-1 do
   for i := 0 to testValuesCount-1 do
     TSQLDBConnector(DBConnector).Connection.ExecuteDirect('insert into FPDEV2 (FT) values (''' + testValues[i] + ''')');
     TSQLDBConnector(DBConnector).Connection.ExecuteDirect('insert into FPDEV2 (FT) values (''' + testValues[i] + ''')');
@@ -935,7 +935,7 @@ var
 
 
 begin
 begin
   CreateTableWithFieldType(ftString,'VARCHAR(9000)');
   CreateTableWithFieldType(ftString,'VARCHAR(9000)');
-  TestFieldDeclaration(ftString,9001);
+  TestFieldDeclaration(ftString,9000*DBConnector.CharSize+1);
 
 
   setlength(s,9000);
   setlength(s,9000);
   for i := 1 to 9000 do
   for i := 1 to 9000 do

+ 14 - 1
packages/fcl-db/tests/toolsunit.pas

@@ -26,6 +26,7 @@ type
        FLogTimeFormat: TFormatSettings; //for error logging only
        FLogTimeFormat: TFormatSettings; //for error logging only
        FFormatSettings: TFormatSettings;
        FFormatSettings: TFormatSettings;
        FChangedFieldDataset : boolean;
        FChangedFieldDataset : boolean;
+       function GetCharSize: integer;
      protected
      protected
        FChangedDatasets : array[0..MaxDataSet] of boolean;
        FChangedDatasets : array[0..MaxDataSet] of boolean;
        FUsedDatasets : TFPList;
        FUsedDatasets : TFPList;
@@ -78,6 +79,7 @@ type
        procedure StopTest(TestName: string);
        procedure StopTest(TestName: string);
        property TestUniDirectional: boolean read GetTestUniDirectional write SetTestUniDirectional;
        property TestUniDirectional: boolean read GetTestUniDirectional write SetTestUniDirectional;
        property FormatSettings: TFormatSettings read FFormatSettings;
        property FormatSettings: TFormatSettings read FFormatSettings;
+       property CharSize: integer read GetCharSize;
      end;
      end;
 
 
   { TTestDataLink }
   { TTestDataLink }
@@ -241,6 +243,7 @@ function TimeStringToDateTime(d: String): TDateTime;
 function StringToByteArray(const s: ansistring): Variant;
 function StringToByteArray(const s: ansistring): Variant;
 function StringToBytes(const s: ansistring): TBytes;
 function StringToBytes(const s: ansistring): TBytes;
 
 
+
 implementation
 implementation
 
 
 uses
 uses
@@ -292,7 +295,7 @@ begin
   raise exception.create('Connector does not support tests for unidirectional datasets');
   raise exception.create('Connector does not support tests for unidirectional datasets');
 end;
 end;
 
 
-procedure TDBConnector.DataEvent(dataset : tdataset);
+procedure TDBConnector.DataEvent(dataset: TDataset);
 begin
 begin
   DataEvents := DataEvents + 'DataEvent' + ';';
   DataEvents := DataEvents + 'DataEvent' + ';';
 end;
 end;
@@ -382,6 +385,16 @@ begin
     end;
     end;
 end;
 end;
 
 
+function TDBConnector.GetCharSize: integer;
+begin
+  case LowerCase(dbcharset) of
+    'utf8','utf-8','utf8mb4':
+      Result := 4;
+    else
+      Result := 1;
+  end;
+end;
+
 
 
 { TTestDataLink }
 { TTestDataLink }