Commits

Anonymous committed 60fd626

extended vfptest

Comments (0)

Files changed (2)

dbasetests/vfptest.lpi

     <RunParams>
       <local>
         <FormatVersion Value="1"/>
-        <CommandLineParams Value="w32_examples.dbf"/>
       </local>
     </RunParams>
     <Units Count="1">
       <IncludeFiles Value="$(ProjOutDir)"/>
       <UnitOutputDirectory Value="lib\$(TargetCPU)-$(TargetOS)"/>
     </SearchPaths>
-    <Linking>
-      <Debugging>
-        <DebugInfoType Value="dsDwarf2Set"/>
-      </Debugging>
-    </Linking>
     <Other>
       <CompilerMessages>
         <MsgFileName Value=""/>

dbasetests/vfptest.lpr

   SysUtils,dateutils;
 
 procedure CreateDBF(FileName: string; TableLevel: integer);
+const
+  UseID=true;
+  UseName= true;
+  UseFloater=true;
+  UseMyMemo=true;
+  UseBCDF=false;
 var
   NewDBF: TDBF;
   i: integer;
   try
     NewDBF.TableLevel:=TableLevel;
     NewDBF.TableName:=FileName;
-    NewDBF.FieldDefs.Add('ID', ftInteger);
-    NewDBF.FieldDefs.Add('NAME', ftString, 5);
+    writeln('Creating ',FileName,' with table level ',NewDBF.TableLevel);
+    if UseID then
+      NewDBF.FieldDefs.Add('ID', ftInteger);
+    if UseName then
+      NewDBF.FieldDefs.Add('NAME', ftString, 5);
+    if UseFloater then
+      NewDBF.FieldDefs.Add('FLOATER', ftFloat);
+    if UseMyMemo then
+      NewDBF.FieldDefs.Add('MYMEMO', ftMemo);
+    // Only in visual foxpro ('Y' field)
+    if (TableLevel>=30) and (UseBCDF) then
+      NewDBF.FieldDefs.Add('BCDF',ftBCD);
     NewDBF.CreateTable;
     NewDBF.Open;
-    writeln('Creating ',FileName,' with table level ',NewDBF.TableLevel);
     writeln('Codepage: ',NewDBF.CodePage);
-    for i := 1 to 9 do
+    for i := 1 to 5 do //keep size manageable until we have working files
     begin
       NewDBF.Append;
-      NewDBF.FieldByName('ID').AsInteger := i;
-      NewDBF.FieldByName('NAME').AsString := 'Test' + IntToStr(i);
+      if UseID then
+        NewDBF.FieldByName('ID').AsInteger := i;
+      if UseName then
+        NewDBF.FieldByName('NAME').AsString := 'Test' + IntToStr(i);
+      if UseFloater then
+        NewDBF.FieldByName('FLOATER').AsFloat := 2/i;
+      if UseMyMemo then
+        NewDBF.FieldByName('MYMEMO').AsString := 'Test' + IntToStr(i);
+      // Only in visual foxpro ('Y' field)
+      if (TableLevel>=30) and (UseBCDF) then
+        NewDBF.FieldByName('BCDF').AsCurrency:= 2/i;
       NewDBF.Post;
     end;
+    writeln('After assigning fields & data: tablelevel: ',NewDBF.TableLevel);
     NewDBF.Close;
   finally
     NewDBF.Free;
   MyDbf: TDbf;
   RecCount: integer;
   SomeDate: TDateTime;
+
+procedure w32_functionstest;
 begin
-  if paramstr(1)='--create' then
+  if lowercase(mydbf.tablename)='w32_functions.dbf' then
+  begin
+    SomeDate:=ScanDateTime('yyyymmdd hhnnss','20051216 154425');
+    if SomeDate=mydbf.FieldByName('MODIFIED').AsDateTime then
+      writeln('modified field is equal to somedate!');
+    {
+    if mydbf.fieldbyname('EXAMPLEID').Asinteger=503 then
+      begin
+        somedate:=mydbf.FieldByName('MODIFIED').AsDateTime;
+        writeln('Copied modified date value which is: ');
+        writeln(FormatDateTime('yyyymmdd hhnnss zzzz',SomeDate));
+      end;
+    }
+  end;
+end;
+
+procedure w32_examplestest;
+begin
+  if lowercase(mydbf.tablename)='w32_examples.dbf' then
+  begin
+    writeln('Testing locate:');
+    try
+      writeln('Recno is now: '+inttostr(MyDBF.RecNo));
+      SomeDate:=ScanDateTime('yyyymmdd hhnnss zzz','20051216 154425 999');
+      writeln('trying to find modified at date '+FormatDateTime('yyyymmdd hhnnss zzz',SomeDate));
+      if MyDBF.Locate('MODIFIED',SomeDate,[]) then
+      begin
+        writeln('Recno is now: '+inttostr(MyDBF.RecNo));
+        PrintRecord(MyDBF,RecCount)
+      end
+      else
+      begin
+        writeln('Locate did not work/find anything.');
+      end;
+
+      writeln('Testing locate partial key with inexact date which should fail:');
+      writeln('Recno is now: '+inttostr(MyDBF.RecNo));
+      SomeDate:=ScanDateTime('yyyymmdd hhnnss zzz','20051216 154425 000');
+      writeln('trying to find modified at/after '+FormatDateTime('yyyymmdd hhnnss zzz',SomeDate));
+      if MyDBF.Locate('MODIFIED',SomeDate,[loPartialKey]) then
+      begin
+        writeln('Recno is now: '+inttostr(MyDBF.RecNo));
+        PrintRecord(MyDBF,RecCount)
+      end
+      else
+      begin
+        writeln('Locate partial key did not work/find anything.');
+      end;
+      writeln('End locate partial test');
+
+      writeln('Testing locate partial key with inexact string which should work:');
+      writeln('Recno is now: '+inttostr(MyDBF.RecNo));
+      writeln('trying to find EXAMPLENAM GDI+');
+      if MyDBF.Locate('EXAMPLENAM','GDI+',[loPartialKey]) then
+      begin
+        writeln('Recno is now: '+inttostr(MyDBF.RecNo));
+        PrintRecord(MyDBF,RecCount)
+      end
+      else
+      begin
+        writeln('Locate partial key did not work/find anything.');
+      end;
+      writeln('End locate partial test');
+    except
+      on E: EDbfError do
+      begin
+        writeln('Locate test: dbf error '+E.Message);
+      end;
+      on F: EDatabaseError do
+      begin
+        writeln('Locate test: database error '+F.Message);
+      end;
+    end;
+  //w32_examples.dbf
+  end;
+end;
+
+procedure w32_ordersstest;
+begin
+  if lowercase(mydbf.tablename)='orders.dbf' then
+  begin
+    //todo: set descending index
+    writeln('Testing locate for orders:');
+    try
+      mydbf.AddIndex('orderiddesc','ORDER_ID',[ixDescending]);
+      writeln('Recno is now: '+inttostr(MyDBF.RecNo));
+
+      writeln('Testing locate partial key with inexact orderid which should fail:');
+      writeln('Recno is now: '+inttostr(MyDBF.RecNo));
+      writeln('trying to find ORDER_ID at/after '+inttostr(10006));
+      if MyDBF.Locate('ORDER_ID',10006,[loPartialKey]) then
+      begin
+        writeln('Recno is now: '+inttostr(MyDBF.RecNo));
+        PrintRecord(MyDBF,RecCount)
+      end
+      else
+      begin
+        writeln('Locate partial key did not work/find anything.');
+      end;
+      writeln('End locate partial test');
+
+    except
+      on E: EDbfError do
+      begin
+        writeln('Locate test: dbf error '+E.Message);
+      end;
+      on F: EDatabaseError do
+      begin
+        writeln('Locate test: database error '+F.Message);
+      end;
+    end;
+  //orders.dbf
+  end;
+end;
+
+begin
+  // Don't create if we specify one dbf to read as paramstr(1)
+  if (paramstr(1)='--create') or (paramstr(1)='') then
   begin
     writeln('** Going to create databases: ');
     CreateDBF('foxpro.dbf',25);
+    CreateDBF('vfoxpro.dbf',30);
+    CreateDBF('dbase7.dbf',7);
     CreateDBF('dbase4.dbf',4);
-    exit;
+    CreateDBF('dbase3.dbf',3);
   end;
 
-  DBFs:=TStringList.Create;
-  try
-    // Argument 1: dbf file name; if not given, show all names in directory
-    if Paramstr(1)='' then
-      ListDBFs(DBFs)
-    else
-      // If dbf specified, only show for that one
-      DBFs.Add(ExpandFileName(paramstr(1)));
-    for DBFFile:=0 to DBFs.Count-1 do
-    begin
-      MyDbf := TDbf.Create(nil);
-      try
-        MyDbf.FilePath := ExtractFilePath(DBFs[DBFFile]);
-        MyDbf.TableName := ExtractFileName(DBFs[DBFFile]);
-        MyDbf.ReadOnly:=true;
-        writeln('*** Opening: '+DBFs[DBFFile]);
-        MyDbf.Open;
-        writeln('Database tablelevel: '+inttostr(MyDbf.TableLevel));
-        //MyDBF.Filter:='DTOS(MODIFIED) > "20060102 163400"';
-        //MyDBF.Filtered:=true;
-        //todo: test multiple locate
-        RecCount:=1;
-        while not(MyDbf.EOF) do
-        begin
-          PrintRecord(MyDBF, RecCount);
-
-          if lowercase(mydbf.tablename)='w32_functions.dbf' then
-          begin
-            SomeDate:=ScanDateTime('yyyymmdd hhnnss','20051216 154425');
-            if SomeDate=mydbf.FieldByName('MODIFIED').AsDateTime then
-              writeln('modified field is equal to somedate!');
-            {
-            if mydbf.fieldbyname('EXAMPLEID').Asinteger=503 then
-              begin
-                somedate:=mydbf.FieldByName('MODIFIED').AsDateTime;
-                writeln('Copied modified date value which is: ');
-                writeln(FormatDateTime('yyyymmdd hhnnss zzzz',SomeDate));
-              end;
-            }
-          end;
-          MyDBF.Next;
-          RecCount:=RecCount+1;
-          writeln('');
-        end;
-
-        if lowercase(mydbf.tablename)='w32_examples.dbf' then
-        begin
-          writeln('Testing locate:');
+  begin
+    DBFs:=TStringList.Create;
+    try
+      // Argument 1: dbf file name; if not given, show all names in directory
+      if Paramstr(1)='' then
+        ListDBFs(DBFs)
+      else
+        // If dbf specified, only show for that one
+        DBFs.Add(ExpandFileName(paramstr(1)));
+      for DBFFile:=0 to DBFs.Count-1 do
+      begin
+        MyDbf := TDbf.Create(nil);
+        try
           try
-            writeln('Recno is now: '+inttostr(MyDBF.RecNo));
-            SomeDate:=ScanDateTime('yyyymmdd hhnnss zzz','20051216 154425 999');
-            writeln('trying to find modified at date '+FormatDateTime('yyyymmdd hhnnss zzz',SomeDate));
-            if MyDBF.Locate('MODIFIED',SomeDate,[]) then
+            MyDbf.FilePath := ExtractFilePath(DBFs[DBFFile]);
+            MyDbf.TableName := ExtractFileName(DBFs[DBFFile]);
+            MyDbf.ReadOnly:=true;
+            writeln('*** Opening: '+DBFs[DBFFile]);
+            MyDbf.Open;
+            writeln('Database tablelevel: '+inttostr(MyDbf.TableLevel));
+            //MyDBF.Filter:='DTOS(MODIFIED) > "20060102 163400"';
+            //MyDBF.Filtered:=true;
+            //todo: test multiple locate
+            RecCount:=1;
+            while not(MyDbf.EOF) do
             begin
-              writeln('Recno is now: '+inttostr(MyDBF.RecNo));
-              PrintRecord(MyDBF,RecCount)
-            end
-            else
-            begin
-              writeln('Locate did not work/find anything.');
+              PrintRecord(MyDBF, RecCount);
+              //Some extra tests for specific dbfs
+              w32_functionstest;
+              MyDBF.Next;
+              RecCount:=RecCount+1;
+              writeln('');
             end;
 
-            writeln('Testing locate partial key with inexact date which should fail:');
-            writeln('Recno is now: '+inttostr(MyDBF.RecNo));
-            SomeDate:=ScanDateTime('yyyymmdd hhnnss zzz','20051216 154425 000');
-            writeln('trying to find modified at/after '+FormatDateTime('yyyymmdd hhnnss zzz',SomeDate));
-            if MyDBF.Locate('MODIFIED',SomeDate,[loPartialKey]) then
+            //another set of tests for a specific file
+            w32_examplestest;
+
+            //and another one
+            w32_ordersstest;
+
+            MyDbf.Close;
+          except
+            on E: Exception do
             begin
-              writeln('Recno is now: '+inttostr(MyDBF.RecNo));
-              PrintRecord(MyDBF,RecCount)
-            end
-            else
-            begin
-              writeln('Locate partial key did not work/find anything.');
-            end;
-            writeln('End locate partial test');
-
-            writeln('Testing locate partial key with inexact string which should work:');
-            writeln('Recno is now: '+inttostr(MyDBF.RecNo));
-            writeln('trying to find EXAMPLENAM GDI+');
-            if MyDBF.Locate('EXAMPLENAM','GDI+',[loPartialKey]) then
-            begin
-              writeln('Recno is now: '+inttostr(MyDBF.RecNo));
-              PrintRecord(MyDBF,RecCount)
-            end
-            else
-            begin
-              writeln('Locate partial key did not work/find anything.');
-            end;
-            writeln('End locate partial test');
-          except
-            on E: EDbfError do
-            begin
-              writeln('Locate test: dbf error '+E.Message);
-            end;
-            on F: EDatabaseError do
-            begin
-              writeln('Locate test: database error '+F.Message);
+              writeln('File ',DBFFile,': error ',E.Message);
             end;
           end;
-        //w32_examples.dbf
+        finally
+          MyDbf.Free;
         end;
-
-        if lowercase(mydbf.tablename)='orders.dbf' then
-        begin
-          //todo: set descending index
-          writeln('Testing locate for orders:');
-          try
-            mydbf.AddIndex('orderiddesc','ORDER_ID',[ixDescending]);
-            writeln('Recno is now: '+inttostr(MyDBF.RecNo));
-
-            writeln('Testing locate partial key with inexact orderid which should fail:');
-            writeln('Recno is now: '+inttostr(MyDBF.RecNo));
-            writeln('trying to find ORDER_ID at/after '+inttostr(10006));
-            if MyDBF.Locate('ORDER_ID',10006,[loPartialKey]) then
-            begin
-              writeln('Recno is now: '+inttostr(MyDBF.RecNo));
-              PrintRecord(MyDBF,RecCount)
-            end
-            else
-            begin
-              writeln('Locate partial key did not work/find anything.');
-            end;
-            writeln('End locate partial test');
-
-          except
-            on E: EDbfError do
-            begin
-              writeln('Locate test: dbf error '+E.Message);
-            end;
-            on F: EDatabaseError do
-            begin
-              writeln('Locate test: database error '+F.Message);
-            end;
-          end;
-        //orders.dbf
-        end;
-        MyDbf.Close;
-      finally
-        MyDbf.Free;
       end;
+    finally
+      DBFs.Free;
     end;
-  finally
-    DBFs.Free;
   end;
+  {
+  writeln('Press enter to continue.');
+  readln;
+  }
 end.