From 25f33e77d2254791d76cc84f0f9e67e9cccf1a67 Mon Sep 17 00:00:00 2001 From: jaybinks Date: Thu, 6 Mar 2008 10:58:54 +0000 Subject: added first steps to building some unit tests. git-svn-id: svn://svn.code.sf.net/p/ultrastardx/svn/trunk@920 b956fd51-792f-4845-bead-9b4dfca2ff2c --- Game/Code/UnitTests/switches.inc | 0 Game/Code/UnitTests/test_libraries.compiled | 5 + Game/Code/UnitTests/test_libraries.lpi | 299 ++++++++++++++++++++++++++++ Game/Code/UnitTests/test_libraries.lpi.bak | 299 ++++++++++++++++++++++++++++ Game/Code/UnitTests/test_libraries.lpr | 31 +++ Game/Code/UnitTests/testsqllite.pas | 84 ++++++++ Game/Code/UnitTests/testsqllite.ppu | Bin 0 -> 2366 bytes 7 files changed, 718 insertions(+) create mode 100644 Game/Code/UnitTests/switches.inc create mode 100644 Game/Code/UnitTests/test_libraries.compiled create mode 100644 Game/Code/UnitTests/test_libraries.lpi create mode 100644 Game/Code/UnitTests/test_libraries.lpi.bak create mode 100644 Game/Code/UnitTests/test_libraries.lpr create mode 100644 Game/Code/UnitTests/testsqllite.pas create mode 100644 Game/Code/UnitTests/testsqllite.ppu (limited to 'Game/Code/UnitTests') diff --git a/Game/Code/UnitTests/switches.inc b/Game/Code/UnitTests/switches.inc new file mode 100644 index 00000000..e69de29b diff --git a/Game/Code/UnitTests/test_libraries.compiled b/Game/Code/UnitTests/test_libraries.compiled new file mode 100644 index 00000000..6efc7c42 --- /dev/null +++ b/Game/Code/UnitTests/test_libraries.compiled @@ -0,0 +1,5 @@ + + + + + diff --git a/Game/Code/UnitTests/test_libraries.lpi b/Game/Code/UnitTests/test_libraries.lpi new file mode 100644 index 00000000..cc3a6ddf --- /dev/null +++ b/Game/Code/UnitTests/test_libraries.lpi @@ -0,0 +1,299 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Game/Code/UnitTests/test_libraries.lpi.bak b/Game/Code/UnitTests/test_libraries.lpi.bak new file mode 100644 index 00000000..aa876577 --- /dev/null +++ b/Game/Code/UnitTests/test_libraries.lpi.bak @@ -0,0 +1,299 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Game/Code/UnitTests/test_libraries.lpr b/Game/Code/UnitTests/test_libraries.lpr new file mode 100644 index 00000000..3e3ae380 --- /dev/null +++ b/Game/Code/UnitTests/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/Game/Code/UnitTests/testsqllite.pas b/Game/Code/UnitTests/testsqllite.pas new file mode 100644 index 00000000..b1b682d2 --- /dev/null +++ b/Game/Code/UnitTests/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. + diff --git a/Game/Code/UnitTests/testsqllite.ppu b/Game/Code/UnitTests/testsqllite.ppu new file mode 100644 index 00000000..be4403f6 Binary files /dev/null and b/Game/Code/UnitTests/testsqllite.ppu differ -- cgit v1.2.3