From 4e4e213f8978e5c9e36e0923a0476ca0ae9aa4cf Mon Sep 17 00:00:00 2001 From: k-m_schindler Date: Wed, 27 Aug 2008 15:02:16 +0000 Subject: rename UnitTests git-svn-id: svn://svn.code.sf.net/p/ultrastardx/svn/trunk@1311 b956fd51-792f-4845-bead-9b4dfca2ff2c --- src/unit-tests/switches.inc | 0 src/unit-tests/test_libraries.lpi | 299 ++++++++++++++++++++++++++++++++++++++ src/unit-tests/test_libraries.lpr | 31 ++++ src/unit-tests/testsqllite.pas | 84 +++++++++++ 4 files changed, 414 insertions(+) create mode 100644 src/unit-tests/switches.inc create mode 100644 src/unit-tests/test_libraries.lpi create mode 100644 src/unit-tests/test_libraries.lpr create mode 100644 src/unit-tests/testsqllite.pas (limited to 'src/unit-tests') diff --git a/src/unit-tests/switches.inc b/src/unit-tests/switches.inc new file mode 100644 index 00000000..e69de29b diff --git a/src/unit-tests/test_libraries.lpi b/src/unit-tests/test_libraries.lpi new file mode 100644 index 00000000..cc3a6ddf --- /dev/null +++ b/src/unit-tests/test_libraries.lpi @@ -0,0 +1,299 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/unit-tests/test_libraries.lpr b/src/unit-tests/test_libraries.lpr new file mode 100644 index 00000000..3e3ae380 --- /dev/null +++ b/src/unit-tests/test_libraries.lpr @@ -0,0 +1,31 @@ +program Test_Libraries; + +{$mode objfpc}{$H+} + +uses + Classes, + consoletestrunner, + TestSQLLite, + SQLite3 in '../lib/SQLite/SQLite3.pas', + + SQLiteTable3 in '../lib/SQLite/SQLiteTable3.pas'; + +type + + { TLazTestRunner } + + TMyTestRunner = class(TTestRunner) + protected + // override the protected methods of TTestRunner to customize its behavior + end; + +var + Application: TMyTestRunner; + +begin + Application := TMyTestRunner.Create(nil); + Application.Initialize; + Application.Title := 'FPCUnit Console test runner'; + Application.Run; + Application.Free; +end. diff --git a/src/unit-tests/testsqllite.pas b/src/unit-tests/testsqllite.pas new file mode 100644 index 00000000..b1b682d2 --- /dev/null +++ b/src/unit-tests/testsqllite.pas @@ -0,0 +1,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. + -- cgit v1.2.3