aboutsummaryrefslogtreecommitdiffstats
path: root/VideoPreview/test/testsqllite.pas
blob: b1b682d2c932b697d7dc799b4ecca6b7558c6e3e (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
unit TestSQLLite;

{$mode objfpc}{$H+}

interface

uses
  Classes, SysUtils, fpcunit, testutils, testregistry, SQLiteTable3, unix;

type

  TTest_SqlLite= class(TTestCase)
  private
    fSQLLite  : TSQLiteDatabase;
    fFileName : string;
  protected
    procedure SetUp; override;
    procedure TearDown; override; 
  published
    procedure Test_Random_TableExists;
    procedure Test_Delete_NonExistant_Table;
    procedure Test_TableExists_On_0Length_File;
  end; 

implementation

procedure TTest_SqlLite.Test_Random_TableExists;
begin
  deletefile( fFileName );
  fSQLLite  := TSQLiteDatabase.Create( fFileName );

  // Test if some random table exists
  check( not fSQLLite.TableExists( 'testTable'+floattostr(now()) ) , 'Randomly Named Table Should NOT Exists (In an empty database file)' );
end; 

procedure TTest_SqlLite.Test_Delete_NonExistant_Table;
var
  lSQL : String;
begin
  deletefile( fFileName );
  fSQLLite  := TSQLiteDatabase.Create( fFileName );
  try
    lSQL := 'DROP TABLE testtable';
    fSQLLite.execsql( lSQL );
  except
    exit;
  end;

  Fail('SQLLite did not except when trying to delete a non existant table' );
end;

procedure TTest_SqlLite.Test_TableExists_On_0Length_File;
var
  lSQL : String;
begin
  deletefile( fFileName );
  shell('cat /dev/null > '+fFileName);
  
  if not fileexists( fFileName ) then
    Fail('0 Length file was not created... oops' );
    
  fSQLLite  := TSQLiteDatabase.Create( fFileName );

  check( not fSQLLite.TableExists( 'testTable' ) , 'Randomly Named Table Should NOT Exists' );
end;


procedure TTest_SqlLite.SetUp; 
begin
  fFileName := 'test.db';
//  fSQLLite  := TSQLiteDatabase.Create( fFileName );
end; 


procedure TTest_SqlLite.TearDown; 
begin
  freeandnil( fSQLLite );
end; 

initialization

  RegisterTest(TTest_SqlLite); 
end.