|
@@ -8,7 +8,7 @@ interface
|
|
|
|
|
|
uses
|
|
uses
|
|
fpcunit, testutils, testregistry, testdecorator,
|
|
fpcunit, testutils, testregistry, testdecorator,
|
|
- Classes, SysUtils;
|
|
|
|
|
|
+ Classes, SysUtils, db;
|
|
|
|
|
|
type
|
|
type
|
|
|
|
|
|
@@ -16,6 +16,7 @@ type
|
|
|
|
|
|
TTestBasics = class(TTestCase)
|
|
TTestBasics = class(TTestCase)
|
|
private
|
|
private
|
|
|
|
+ function CreateDatasetWith3Fields: TDataset;
|
|
protected
|
|
protected
|
|
published
|
|
published
|
|
procedure TestParseSQL;
|
|
procedure TestParseSQL;
|
|
@@ -25,16 +26,36 @@ type
|
|
procedure TestGetParamList;
|
|
procedure TestGetParamList;
|
|
procedure TestGetFieldList;
|
|
procedure TestGetFieldList;
|
|
procedure TestExtractFieldName; //move record then copy. Is copy identical? Has record position changed?
|
|
procedure TestExtractFieldName; //move record then copy. Is copy identical? Has record position changed?
|
|
|
|
+ procedure TestCheckFieldNames;
|
|
|
|
+ procedure TestFindField;
|
|
end;
|
|
end;
|
|
|
|
|
|
implementation
|
|
implementation
|
|
|
|
|
|
-uses db, toolsunit;
|
|
|
|
|
|
+uses toolsunit;
|
|
|
|
|
|
Type HackedDataset = class(TDataset);
|
|
Type HackedDataset = class(TDataset);
|
|
|
|
|
|
{ TTestBasics }
|
|
{ TTestBasics }
|
|
|
|
|
|
|
|
+function TTestBasics.CreateDatasetWith3Fields: TDataset;
|
|
|
|
+var
|
|
|
|
+ F: TField;
|
|
|
|
+begin
|
|
|
|
+ Result := TDataSet.Create(nil);
|
|
|
|
+ F := TIntegerField.Create(Result);
|
|
|
|
+ F.FieldName := 'Field1';
|
|
|
|
+ F.DataSet := Result;
|
|
|
|
+
|
|
|
|
+ F := TIntegerField.Create(Result);
|
|
|
|
+ F.FieldName := 'Field2';
|
|
|
|
+ F.DataSet := Result;
|
|
|
|
+
|
|
|
|
+ F := TIntegerField.Create(Result);
|
|
|
|
+ F.FieldName := 'Field3';
|
|
|
|
+ F.DataSet := Result;
|
|
|
|
+end;
|
|
|
|
+
|
|
procedure TTestBasics.TestParseSQL;
|
|
procedure TTestBasics.TestParseSQL;
|
|
var Params : TParams;
|
|
var Params : TParams;
|
|
ReplStr : string;
|
|
ReplStr : string;
|
|
@@ -214,24 +235,11 @@ end;
|
|
procedure TTestBasics.TestGetFieldList;
|
|
procedure TTestBasics.TestGetFieldList;
|
|
var
|
|
var
|
|
ds: TDataSet;
|
|
ds: TDataSet;
|
|
- F: TField;
|
|
|
|
List: TList;
|
|
List: TList;
|
|
ExceptionRaised: Boolean;
|
|
ExceptionRaised: Boolean;
|
|
begin
|
|
begin
|
|
- ds := TDataSet.Create(nil);
|
|
|
|
|
|
+ ds := CreateDatasetWith3Fields;
|
|
try
|
|
try
|
|
- F := TIntegerField.Create(ds);
|
|
|
|
- F.FieldName := 'Field1';
|
|
|
|
- F.DataSet := ds;
|
|
|
|
-
|
|
|
|
- F := TIntegerField.Create(ds);
|
|
|
|
- F.FieldName := 'Field2';
|
|
|
|
- F.DataSet := ds;
|
|
|
|
-
|
|
|
|
- F := TIntegerField.Create(ds);
|
|
|
|
- F.FieldName := 'Field3';
|
|
|
|
- F.DataSet := ds;
|
|
|
|
-
|
|
|
|
List := TList.Create;
|
|
List := TList.Create;
|
|
try
|
|
try
|
|
//should not
|
|
//should not
|
|
@@ -376,6 +384,61 @@ begin
|
|
AssertEquals('xxx', FieldName);
|
|
AssertEquals('xxx', FieldName);
|
|
end;
|
|
end;
|
|
|
|
|
|
|
|
+procedure TTestBasics.TestCheckFieldNames;
|
|
|
|
+var
|
|
|
|
+ ds: TDataSet;
|
|
|
|
+ ExceptionRaised: Boolean;
|
|
|
|
+begin
|
|
|
|
+ ds := CreateDatasetWith3Fields;
|
|
|
|
+ try
|
|
|
|
+ ExceptionRaised := False;
|
|
|
|
+ try
|
|
|
|
+ ds.Fields.CheckFieldNames('');
|
|
|
|
+ except
|
|
|
|
+ ExceptionRaised := True;
|
|
|
|
+ end;
|
|
|
|
+ AssertFalse(ExceptionRaised);
|
|
|
|
+
|
|
|
|
+ ExceptionRaised := False;
|
|
|
|
+ try
|
|
|
|
+ ds.Fields.CheckFieldNames('Field1;Field2');
|
|
|
|
+ except
|
|
|
|
+ ExceptionRaised := True;
|
|
|
|
+ end;
|
|
|
|
+ AssertFalse(ExceptionRaised);
|
|
|
|
+
|
|
|
|
+ ExceptionRaised := False;
|
|
|
|
+ try
|
|
|
|
+ ds.Fields.CheckFieldNames('Field1;NonExistentField');
|
|
|
|
+ except
|
|
|
|
+ ExceptionRaised := True;
|
|
|
|
+ end;
|
|
|
|
+ AssertTrue(ExceptionRaised);
|
|
|
|
+ finally
|
|
|
|
+ ds.Destroy;
|
|
|
|
+ end;
|
|
|
|
+end;
|
|
|
|
+
|
|
|
|
+procedure TTestBasics.TestFindField;
|
|
|
|
+var
|
|
|
|
+ ds: TDataSet;
|
|
|
|
+ F: TField;
|
|
|
|
+begin
|
|
|
|
+ ds := CreateDatasetWith3Fields;
|
|
|
|
+ try
|
|
|
|
+ F := ds.FindField('');
|
|
|
|
+ AssertTrue(F = nil);
|
|
|
|
+
|
|
|
|
+ F := ds.FindField('field3');
|
|
|
|
+ AssertTrue(F <> nil);
|
|
|
|
+
|
|
|
|
+ F := ds.FindField('NonExistentField');
|
|
|
|
+ AssertTrue(F = nil);
|
|
|
|
+ finally
|
|
|
|
+ ds.Destroy;
|
|
|
|
+ end;
|
|
|
|
+end;
|
|
|
|
+
|
|
initialization
|
|
initialization
|
|
RegisterTest(TTestBasics);
|
|
RegisterTest(TTestBasics);
|
|
end.
|
|
end.
|