View Issue Details

IDProjectCategoryView StatusLast Update
0032347FPCDatabasepublic2019-09-08 12:31
ReporterLuiz Americo Assigned ToMichael Van Canneyt  
PrioritynormalSeverityminorReproducibilityalways
Status resolvedResolutionfixed 
Fixed in Version3.3.1 
Summary0032347: Add specifics tests for Sqlite3Dataset
DescriptionThe attached patch add specific unit tests for TSqlite3Dataset, specially for rev 37079
TagsNo tags attached.
Fixed in Revision42945
FPCOldBugId0
FPCTarget3.2.0
Attached Files

Activities

Luiz Americo

2017-08-27 21:54

developer  

sqlite3tests.diff (5,401 bytes)   
Index: packages/fcl-db/tests/dbtestframework_gui.lpr
===================================================================
--- packages/fcl-db/tests/dbtestframework_gui.lpr	(revision 37078)
+++ packages/fcl-db/tests/dbtestframework_gui.lpr	(working copy)
@@ -26,6 +26,7 @@
   SdfDSToolsUnit,
 {$IFDEF TEST_SQLITE3DS}
   Sqlite3DSToolsUnit,
+  TestSpecificTSqlite3Dataset,
 {$ENDIF}
   // DB unittest
   TestBasics,
Index: packages/fcl-db/tests/sqlite3dstoolsunit.pas
===================================================================
--- packages/fcl-db/tests/sqlite3dstoolsunit.pas	(revision 37078)
+++ packages/fcl-db/tests/sqlite3dstoolsunit.pas	(working copy)
@@ -119,8 +119,7 @@
          FieldByName('FMEMO').AsString := testStringValues[i];
          Post;
        end;
-       if not ApplyUpdates then
-         raise Exception.Create('Error in ApplyUpdates: ' + FieldDataset.ReturnString);
+       ApplyUpdates;
        Destroy;
      end;
   except
@@ -200,4 +199,4 @@
 
 initialization
   RegisterClass(TSqlite3DSDBConnector);
-end.
\ No newline at end of file
+end.
Index: packages/fcl-db/tests/testspecifictsqlite3dataset.pas
===================================================================
--- packages/fcl-db/tests/testspecifictsqlite3dataset.pas	(revision 0)
+++ packages/fcl-db/tests/testspecifictsqlite3dataset.pas	(working copy)
@@ -0,0 +1,141 @@
+unit TestSpecificTSqlite3Dataset;
+
+{$mode objfpc}{$H+}
+
+interface
+
+uses
+  Classes, SysUtils, ToolsUnit, Sqlite3DS;
+
+type
+
+  { TTestSpecificTSqlite3Dataset }
+
+  TTestSpecificTSqlite3Dataset = class(TDBBasicsTestCase)
+  private
+    function CreateMemoryDataset: TSqlite3Dataset;
+  protected
+  published
+    procedure TestApplyUpdates;
+  end;
+
+implementation
+
+uses
+  testregistry;
+
+
+{ TTestSpecificTSqlite3Dataset }
+
+function TTestSpecificTSqlite3Dataset.CreateMemoryDataset: TSqlite3Dataset;
+begin
+  Result := TSqlite3Dataset.Create(nil);
+  Result.FileName := ':memory:';
+  Result.TableName := 'Test';
+  Result.PrimaryKey := 'Id';
+  Result.ExecSQL('Create Table Test (Id INTEGER PRIMARY KEY, Name VARCHAR);');
+end;
+
+procedure TTestSpecificTSqlite3Dataset.TestApplyUpdates;
+var
+  Dataset: TSqlite3Dataset;
+  ExceptionRaised: Boolean;
+begin
+  Dataset := CreateMemoryDataset;
+  try
+    // insert
+    Dataset.Open;
+    CheckEquals(0, Dataset.RecordCount, 'Dataset should be empty');
+    Dataset.Append;
+    Dataset.FieldByName('Name').AsString := 'Luiz';
+    Dataset.Post;
+    Dataset.ApplyUpdates;
+    Dataset.Close;
+    Dataset.Open;
+    CheckEquals(1, Dataset.RecordCount, 'Record count should increase after apply insert updates');
+    CheckEquals('Luiz', Dataset.FieldByName('Name').AsString, 'Record field should be set');
+    // update
+    Dataset.Edit;
+    Dataset.FieldByName('Name').AsString := 'New';
+    Dataset.Post;
+    Dataset.ApplyUpdates;
+    Dataset.Close;
+    Dataset.Open;
+    CheckEquals(1, Dataset.RecordCount, 'Record count should not change after apply update updates');
+    CheckEquals('New', Dataset.FieldByName('Name').AsString, 'Record field should be updated');
+    //delete
+    Dataset.Delete;
+    Dataset.ApplyUpdates;
+    Dataset.Close;
+    Dataset.Open;
+    CheckEquals(0, Dataset.RecordCount, 'Record count should decrease after apply delete updates');
+  finally
+    Dataset.Destroy;
+  end;
+
+  Dataset := CreateMemoryDataset;
+  try
+    Dataset.Open;
+    CheckEquals(0, Dataset.RecordCount, 'Dataset should be empty');
+    Dataset.Append;
+    Dataset.FieldByName('Name').AsString := 'Luiz';
+    Dataset.Post;
+    Dataset.TableName := 'NonExistentTable';
+    ExceptionRaised := False;
+    try
+      Dataset.ApplyUpdates;
+    except
+      ExceptionRaised := True;
+    end;
+    CheckTrue(ExceptionRaised, 'An exception should be raised if TableName is invalid');
+  finally
+    Dataset.Destroy;
+  end;
+
+  Dataset := CreateMemoryDataset;
+  try
+    Dataset.Open;
+    Dataset.Append;
+    Dataset.FieldByName('Name').AsString := 'Luiz';
+    Dataset.Post;
+    Dataset.ApplyUpdates;
+
+    Dataset.Close;
+    Dataset.PrimaryKey := '';
+    Dataset.Open;
+    Dataset.Edit;
+    Dataset.FieldByName('Name').AsString := 'New';
+    Dataset.Post;
+    ExceptionRaised := False;
+    try
+      Dataset.ApplyUpdates;
+    except
+      ExceptionRaised := True;
+    end;
+    CheckTrue(ExceptionRaised, 'An exception should be raised if PrimaryKey is empty');
+
+    Dataset.Close;
+    Dataset.PrimaryKey := 'NonExistingKey';
+    Dataset.Open;
+    Dataset.Edit;
+    Dataset.FieldByName('Name').AsString := 'New';
+    Dataset.Post;
+    ExceptionRaised := False;
+    try
+      Dataset.ApplyUpdates;
+    except
+      ExceptionRaised := True;
+    end;
+    CheckTrue(ExceptionRaised, 'An exception should be raised if PrimaryKey is invalid');
+  finally
+    Dataset.Destroy;
+  end;
+end;
+
+initialization
+
+  if UpperCase(dbconnectorname) = 'SQLITE3DS' then
+    RegisterTestDecorator(TDBBasicsTestSetup, TTestSpecificTSqlite3Dataset);
+
+end.
+

Property changes on: packages\fcl-db\tests\testspecifictsqlite3dataset.pas
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
sqlite3tests.diff (5,401 bytes)   

Michael Van Canneyt

2019-09-08 12:31

administrator   ~0117990

I totally forgot about this patch :(

Tested & applied it, thank you very much !

Issue History

Date Modified Username Field Change
2017-08-27 21:54 Luiz Americo New Issue
2017-08-27 21:54 Luiz Americo File Added: sqlite3tests.diff
2017-08-27 22:35 Michael Van Canneyt Assigned To => Michael Van Canneyt
2017-08-27 22:35 Michael Van Canneyt Status new => assigned
2019-09-08 12:31 Michael Van Canneyt Status assigned => resolved
2019-09-08 12:31 Michael Van Canneyt Resolution open => fixed
2019-09-08 12:31 Michael Van Canneyt Fixed in Version => 3.3.1
2019-09-08 12:31 Michael Van Canneyt Fixed in Revision => 42945
2019-09-08 12:31 Michael Van Canneyt FPCTarget => 3.2.0
2019-09-08 12:31 Michael Van Canneyt Note Added: 0117990