Anonymous avatar Anonymous committed 160c8d5

add tablelevel test, test some more fields

Comments (0)

Files changed (4)

dbasetests/dbftoolsunit.pas

   {$mode objfpc}{$H+}
 {$ENDIF}
 
+// If defined, do not delete the dbf files when done but print out location to stdout:
+{.$DEFINE KEEPDBFFILES}
+
 interface
 
 uses
   // DBF descendant that saves to a temp file and removes file when closed
   TDBFAutoClean = class(TDBF)
   private
-    function GetUserRequestedTableLevel: integer;
+    FCreatedBy: string;
   public
+    // Keeps track of which function created the dataset, useful for troubleshooting
+    property CreatedBy: string read FCreatedBy write FCreatedBy;
     constructor Create;
     constructor Create(AOwner: TComponent); override;
     destructor Destroy; override;
+    function UserRequestedTableLevel: integer;
   end;
 
 implementation
 
-
+uses
+  FmtBCD;
 
 { TDBFAutoClean }
 
-function TDBFAutoClean.GetUserRequestedTableLevel: integer;
+function TDBFAutoClean.UserRequestedTableLevel: integer;
   // User can specify table level as a connector param, e.g.:
   // connectorparams=4
   // If none given, default to DBase IV
   TableLevelProvided: integer;
 begin
   TableLevelProvided := StrToIntDef(dbconnectorparams, 4);
-  if not (TableLevelProvided in [3, 4, 5, 7, TDBF_TABLELEVEL_FOXPRO,
-    TDBF_TABLELEVEL_VISUALFOXPRO]) then
+  if not (TableLevelProvided in [3, 4, 5, 7, 
+    TDBF_TABLELEVEL_FOXPRO, TDBF_TABLELEVEL_VISUALFOXPRO]) then
   begin
     Result := -1; // hope this crashes the tests so user is alerted.
     //Invalid tablelevel specified in connectorparams= field. Aborting
   DBFFileName := GetTempFileName;
   FilePathFull := ExtractFilePath(DBFFileName);
   TableName := ExtractFileName(DBFFileName);
-  TableLevelProvided := GetUserRequestedTableLevel;
+  TableLevelProvided := UserRequestedTableLevel;
   TableLevel := TableLevelProvided;
   CreateTable; //write out header to disk
 end;
 begin
   FileName := AbsolutePath + TableName;
   inherited Destroy;
+  {$IFDEF KEEPDBFFILES}
+  writeln('TDBFAutoClean: file created by ',CreatedBy,' left file: ',FileName);
+  {$ELSE}
   deletefile(FileName);
+  {$ENDIF}
 end;
 
 
   Result := (TDBFAutoClean.Create(nil) as TDataSet);
   with (Result as TDBFAutoclean) do
   begin
+    CreatedBy:='InternalGetNDataset('+inttostr(n)+')';
     FieldDefs.Add('ID', ftInteger);
     FieldDefs.Add('NAME', ftString, 50);
     CreateTable;
   Result := (TDbfAutoClean.Create(nil) as TDataSet);
   with (Result as TDBFAutoClean) do
   begin
+    CreatedBy:='InternalGetFieldDataset';
     FieldDefs.Add('ID', ftInteger);
     FieldDefs.Add('FSTRING', ftString, 10);
     FieldDefs.Add('FSMALLINT', ftSmallint);
       FieldByName('FINTEGER').AsInteger := testIntValues[i];
       FieldByName('FBOOLEAN').AsBoolean := testBooleanValues[i];
       FieldByName('FFLOAT').AsFloat := testFloatValues[i];
+      if (Result as TDBF).TableLevel >= 25 then
+        FieldByName('FCURRENCY').AsCurrency := testCurrencyValues[i];
+      if (Result as TDBF).TableLevel >= 25 then
+        FieldByName('FBCD').AsBCD := StrToBCD(testFmtBCDValues[i], Self.FormatSettings);
       FieldByName('FDATE').AsDateTime := StrToDate(testDateValues[i], 'yyyy/mm/dd', '-');
       FieldByName('FLARGEINT').AsLargeInt := testLargeIntValues[i];
       Post;
Add a comment to this file

dbasetests/dbtestframework_gui.obj

Binary file removed.

Add a comment to this file

dbasetests/dbtestframework_gui.res

Binary file removed.

dbasetests/testspecifictdbf.pas

   TestFramework,
 {$ENDIF FPC}
   Classes, SysUtils,
-  ToolsUnit, dbf, DBFToolsUnit;
+  ToolsUnit, dbf;
 
 type
 
     procedure SetUp; override;
     procedure TearDown; override;
   published
+    // Verifies that requested tablelevel is delivered:
+    procedure TestTableLevel;
     // Create fields using indexdefs:
     procedure TestCreateDatasetFromFielddefs;
     // Specifying fields from field objects
 uses
   variants,
   FmtBCD,
-  db, dbf_common;
+  db, dbf_common, DBFToolsUnit;
 
 { TTestSpecificTDBF }
 
   DBConnector.StopTest;
 end;
 
+procedure TTestSpecificTDBF.TestTableLevel;
+var
+  ds : TDBF;
+begin
+  ds := TDBFAutoClean.Create(nil);
+  DS.FieldDefs.Add('ID',ftInteger);
+  DS.CreateTable;
+  DS.Open;
+  CheckEquals((DS as TDBFAutoClean).UserRequestedTableLevel,DS.TableLevel,'User specified tablelevel should match dbf tablelevel.');
+  DS.Close;
+  ds.free;
+end;
+
 procedure TTestSpecificTDBF.TestCreateDatasetFromFielddefs;
 var
   ds : TDBF;
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.