Database definition & tests organisation

* The main loader script has been updated to generate the list of files
it needs to load automatically. As a consequence, files that contained
manually-maintained lists of scripts have been removed, and definition
directories have been renamed accordingly.

* PostgreSQL extension loading and configuration has been moved to a
separate script to be loaded automatically in the main transaction.

* Data and function definition scripts that had the -data or -functions
suffix have been renamed (the suffix is unnecessary).

* Unit tests have been reorganised to follow the definition's structure.

* Documentation has been improved
This commit is contained in:
Emmanuel BENOîT 2012-01-06 11:19:19 +01:00
parent b054a379a9
commit e50775ec76
112 changed files with 78 additions and 144 deletions
legacyworlds-server-data/db-structure/tests/admin/030-data/110-empires

View file

@ -0,0 +1,191 @@
/*
* Test constraints and foreign keys on emp.resources
*/
BEGIN;
/* We need to create a pair of resources and a pair of empires */
\i utils/strings.sql
\i utils/resources.sql
\i utils/accounts.sql
\i utils/naming.sql
SELECT _create_natural_resources( 2 , 'testResource' );
SELECT _create_emp_names( 2 , 'testUser' );
INSERT INTO emp.empires ( name_id , cash )
SELECT id , 0 FROM naming.empire_names;
/****** TESTS BEGIN HERE ******/
SELECT plan( 16 );
SELECT diag_test_name( 'Valid empire resources record' );
PREPARE _test_this AS
INSERT INTO emp.resources (
empire_id , resource_name_id , empres_possessed , empres_owed
) VALUES (
_get_emp_name( 'testUser1' ) , _get_string( 'testResource1' ) ,
1 , 1
);
SELECT lives_ok( '_test_this' );
DELETE FROM emp.resources;
DEALLOCATE ALL;
INSERT INTO emp.resources (
empire_id , resource_name_id
) VALUES (
_get_emp_name( 'testUser1' ) , _get_string( 'testResource1' )
);
SELECT diag_test_name( 'Default possessed value in empire resources record' );
SELECT results_eq(
$$ SELECT empres_possessed FROM emp.resources $$ ,
$$ VALUES ( 0::DOUBLE PRECISION ) $$
);
SELECT diag_test_name( 'Default owed value in empire resources record' );
SELECT results_eq(
$$ SELECT empres_owed FROM emp.resources $$ ,
$$ VALUES ( 0::DOUBLE PRECISION ) $$
);
DELETE FROM emp.resources;
SELECT diag_test_name( 'NULL empire identifier in empire resources record' );
PREPARE _test_this AS
INSERT INTO emp.resources (
empire_id , resource_name_id , empres_possessed , empres_owed
) VALUES (
NULL , _get_string( 'testResource1' ) ,
1 , 1
);
SELECT throws_ok( '_test_this' , 23502 );
DEALLOCATE ALL;
SELECT diag_test_name( 'Invalid empire identifier in empire resources record' );
PREPARE _test_this AS
INSERT INTO emp.resources (
empire_id , resource_name_id , empres_possessed , empres_owed
) VALUES (
_get_bad_emp_name( ) , _get_string( 'testResource1' ) ,
1 , 1
);
SELECT throws_ok( '_test_this' , 23503 );
DEALLOCATE ALL;
SELECT diag_test_name( 'NULL resource identifier in empire resources record' );
PREPARE _test_this AS
INSERT INTO emp.resources (
empire_id , resource_name_id , empres_possessed , empres_owed
) VALUES (
_get_emp_name( 'testUser1' ) , NULL ,
1 , 1
);
SELECT throws_ok( '_test_this' , 23502 );
DEALLOCATE ALL;
SELECT diag_test_name( 'Invalid resource identifier in empire resources record' );
PREPARE _test_this AS
INSERT INTO emp.resources (
empire_id , resource_name_id , empres_possessed , empres_owed
) VALUES (
_get_emp_name( 'testUser1' ) , _get_bad_string( ) ,
1 , 1
);
SELECT throws_ok( '_test_this' , 23503 );
DEALLOCATE ALL;
SELECT diag_test_name( 'Duplicate empire resources record' );
PREPARE _test_this AS
INSERT INTO emp.resources (
empire_id , resource_name_id , empres_possessed , empres_owed
) VALUES (
_get_emp_name( 'testUser1' ) , _get_string( 'testResource1' ) ,
1 , 1
);
EXECUTE _test_this;
SELECT throws_ok( '_test_this' , 23505 );
DEALLOCATE ALL;
SELECT diag_test_name( 'Empire resources record with same empire but different types of resources' );
PREPARE _test_this AS
INSERT INTO emp.resources (
empire_id , resource_name_id , empres_possessed , empres_owed
) VALUES (
_get_emp_name( 'testUser1' ) , _get_string( 'testResource2' ) ,
1 , 1
);
SELECT lives_ok( '_test_this' );
DEALLOCATE ALL;
SELECT diag_test_name( 'Empire resources record with different empires but same type of resources' );
PREPARE _test_this AS
INSERT INTO emp.resources (
empire_id , resource_name_id , empres_possessed , empres_owed
) VALUES (
_get_emp_name( 'testUser2' ) , _get_string( 'testResource1' ) ,
1 , 1
);
SELECT lives_ok( '_test_this' );
DEALLOCATE ALL;
DELETE FROM emp.resources;
INSERT INTO emp.resources (
empire_id , resource_name_id
) VALUES (
_get_emp_name( 'testUser2' ) , _get_string( 'testResource1' )
);
SELECT diag_test_name( 'Empire deletion succeeds when empire resources records are present' );
PREPARE _test_this AS
DELETE FROM emp.empires WHERE name_id = _get_emp_name( 'testUser2' );
SELECT lives_ok( '_test_this' );
SELECT diag_test_name( 'Empire deletion causes empire resources record deletion' );
SELECT is_empty( 'SELECT * FROM emp.resources' );
DEALLOCATE ALL;
PREPARE _test_this AS
INSERT INTO emp.resources (
empire_id , resource_name_id , empres_possessed
) VALUES (
_get_emp_name( 'testUser1' ) , _get_string( 'testResource1' ) , NULL
);
SELECT diag_test_name( 'NULL possessed value in empire resources record' );
SELECT throws_ok( '_test_this' , 23502 );
DEALLOCATE ALL;
PREPARE _test_this AS
INSERT INTO emp.resources (
empire_id , resource_name_id , empres_possessed
) VALUES (
_get_emp_name( 'testUser1' ) , _get_string( 'testResource1' ) , -1
);
SELECT diag_test_name( 'Negative possessed value in empire resources record' );
SELECT throws_ok( '_test_this' , 23514 );
DEALLOCATE ALL;
PREPARE _test_this AS
INSERT INTO emp.resources (
empire_id , resource_name_id , empres_owed
) VALUES (
_get_emp_name( 'testUser1' ) , _get_string( 'testResource1' ) , NULL
);
SELECT diag_test_name( 'NULL owed value in empire resources record' );
SELECT throws_ok( '_test_this' , 23502 );
DEALLOCATE ALL;
PREPARE _test_this AS
INSERT INTO emp.resources (
empire_id , resource_name_id , empres_owed
) VALUES (
_get_emp_name( 'testUser1' ) , _get_string( 'testResource1' ) , -1
);
SELECT diag_test_name( 'Negative owed value in empire resources record' );
SELECT throws_ok( '_test_this' , 23514 );
DEALLOCATE ALL;
SELECT * FROM finish( );
ROLLBACK;

View file

@ -0,0 +1,119 @@
/*
* Test constraints and foreign keys on emp.mining_settings
*/
BEGIN;
/* We need to create a pair of resources and a pair of empires */
\i utils/strings.sql
\i utils/resources.sql
\i utils/accounts.sql
\i utils/naming.sql
SELECT _create_natural_resources( 2 , 'testResource' );
SELECT _create_emp_names( 2 , 'testUser' );
INSERT INTO emp.empires ( name_id , cash )
SELECT id , 0 FROM naming.empire_names;
/****** TESTS BEGIN HERE ******/
SELECT plan( 10 );
SELECT diag_test_name( 'Valid empire mining settings record' );
PREPARE _test_this AS
INSERT INTO emp.mining_settings(
empire_id , resource_name_id , empmset_weight
) VALUES (
_get_emp_name( 'testUser1' ) , _get_string( 'testResource1' ) , 0
);
SELECT lives_ok( '_test_this' );
SELECT diag_test_name( 'Duplicate empire mining settings record' );
SELECT throws_ok( '_test_this' , 23505 );
DEALLOCATE ALL;
SELECT diag_test_name( 'Empire mining settings records with same empire but different types' );
PREPARE _test_this AS
INSERT INTO emp.mining_settings(
empire_id , resource_name_id , empmset_weight
) VALUES (
_get_emp_name( 'testUser1' ) , _get_string( 'testResource2' ) , 0
);
SELECT lives_ok( '_test_this' );
DEALLOCATE ALL;
SELECT diag_test_name( 'Empire mining settings records with same type but different empires' );
PREPARE _test_this AS
INSERT INTO emp.mining_settings(
empire_id , resource_name_id , empmset_weight
) VALUES (
_get_emp_name( 'testUser2' ) , _get_string( 'testResource1' ) , 0
);
SELECT lives_ok( '_test_this' );
DEALLOCATE ALL;
DELETE FROM emp.mining_settings;
SELECT diag_test_name( 'Empire mining settings record with NULL empire identifier' );
PREPARE _test_this AS
INSERT INTO emp.mining_settings(
empire_id , resource_name_id , empmset_weight
) VALUES (
NULL , _get_string( 'testResource1' ) , 0
);
SELECT throws_ok( '_test_this' , 23502 );
DEALLOCATE ALL;
SELECT diag_test_name( 'Empire mining settings record with invalid empire identifier' );
PREPARE _test_this AS
INSERT INTO emp.mining_settings(
empire_id , resource_name_id , empmset_weight
) VALUES (
_get_bad_emp_name( ) , _get_string( 'testResource1' ) , 0
);
SELECT throws_ok( '_test_this' , 23503 );
DEALLOCATE ALL;
SELECT diag_test_name( 'Empire mining settings record with NULL resource identifier' );
PREPARE _test_this AS
INSERT INTO emp.mining_settings(
empire_id , resource_name_id , empmset_weight
) VALUES (
_get_emp_name( 'testUser1' ) , NULL , 0
);
SELECT throws_ok( '_test_this' , 23502 );
DEALLOCATE ALL;
SELECT diag_test_name( 'Empire mining settings record with invalid resource identifier' );
PREPARE _test_this AS
INSERT INTO emp.mining_settings(
empire_id , resource_name_id , empmset_weight
) VALUES (
_get_emp_name( 'testUser1' ) , _get_bad_string( ) , 0
);
SELECT throws_ok( '_test_this' , 23503 );
DEALLOCATE ALL;
SELECT diag_test_name( 'Empire mining settings record with NULL weight' );
PREPARE _test_this AS
INSERT INTO emp.mining_settings(
empire_id , resource_name_id , empmset_weight
) VALUES (
_get_emp_name( 'testUser1' ) , _get_string( 'testResource1' ) , NULL
);
SELECT throws_ok( '_test_this' , 23502 );
DEALLOCATE ALL;
SELECT diag_test_name( 'Empire mining settings record with weight < 0' );
PREPARE _test_this AS
INSERT INTO emp.mining_settings(
empire_id , resource_name_id , empmset_weight
) VALUES (
_get_emp_name( 'testUser1' ) , _get_string( 'testResource1' ) , -1
);
SELECT throws_ok( '_test_this' , 23514 );
DEALLOCATE ALL;
SELECT * FROM finish( );
ROLLBACK;

View file

@ -0,0 +1,193 @@
/*
* Test constraints and foreign keys on emp.mining_settings
*/
BEGIN;
/* We need to create a pair of resources, a pair of empires, a pair of planets, and resource providers */
\i utils/strings.sql
\i utils/resources.sql
\i utils/accounts.sql
\i utils/naming.sql
\i utils/universe.sql
SELECT _create_natural_resources( 2 , 'testResource' );
SELECT _create_emp_names( 2 , 'testUser' );
INSERT INTO emp.empires ( name_id , cash )
SELECT id , 0 FROM naming.empire_names;
SELECT _create_raw_planets( 2 , 'testPlanet' );
SELECT _create_resource_provider( 'testPlanet1' , 'testResource1' );
SELECT _create_resource_provider( 'testPlanet1' , 'testResource2' );
SELECT _create_resource_provider( 'testPlanet2' , 'testResource1' );
-- No provider for testResource2 on testPlanet2
/****** TESTS BEGIN HERE ******/
SELECT plan( 14 );
SELECT diag_test_name( 'Valid empire planet mining settings record' );
PREPARE _test_this AS
INSERT INTO emp.planet_mining_settings(
empire_id , planet_id ,
resource_name_id , emppmset_weight
) VALUES (
_get_emp_name( 'testUser1' ) , _get_map_name( 'testPlanet1' ) ,
_get_string( 'testResource1' ) , 0
);
SELECT lives_ok( '_test_this' );
SELECT diag_test_name( 'Duplicate empire planet mining settings record' );
SELECT throws_ok( '_test_this' , 23505 );
DEALLOCATE ALL;
SELECT diag_test_name( 'Empire planet mining settings records with different types' );
PREPARE _test_this AS
INSERT INTO emp.planet_mining_settings(
empire_id , planet_id ,
resource_name_id , emppmset_weight
) VALUES (
_get_emp_name( 'testUser1' ) , _get_map_name( 'testPlanet1' ) ,
_get_string( 'testResource2' ) , 0
);
SELECT lives_ok( '_test_this' );
DEALLOCATE ALL;
SELECT diag_test_name( 'Empire planet mining settings records with different empires' );
PREPARE _test_this AS
INSERT INTO emp.planet_mining_settings(
empire_id , planet_id ,
resource_name_id , emppmset_weight
) VALUES (
_get_emp_name( 'testUser2' ) , _get_map_name( 'testPlanet1' ) ,
_get_string( 'testResource1' ) , 0
);
SELECT lives_ok( '_test_this' );
DEALLOCATE ALL;
SELECT diag_test_name( 'Empire planet mining settings records with different planets' );
PREPARE _test_this AS
INSERT INTO emp.planet_mining_settings(
empire_id , planet_id ,
resource_name_id , emppmset_weight
) VALUES (
_get_emp_name( 'testUser1' ) , _get_map_name( 'testPlanet2' ) ,
_get_string( 'testResource1' ) , 0
);
SELECT lives_ok( '_test_this' );
DEALLOCATE ALL;
DELETE FROM emp.mining_settings;
SELECT diag_test_name( 'Empire planet mining setting record with NULL empire identifier' );
PREPARE _test_this AS
INSERT INTO emp.planet_mining_settings(
empire_id , planet_id ,
resource_name_id , emppmset_weight
) VALUES (
NULL , _get_map_name( 'testPlanet2' ) ,
_get_string( 'testResource1' ) , 0
);
SELECT throws_ok( '_test_this' , 23502 );
DEALLOCATE ALL;
SELECT diag_test_name( 'Empire planet mining setting record with invalid empire identifier' );
PREPARE _test_this AS
INSERT INTO emp.planet_mining_settings(
empire_id , planet_id ,
resource_name_id , emppmset_weight
) VALUES (
_get_bad_emp_name( ) , _get_map_name( 'testPlanet2' ) ,
_get_string( 'testResource1' ) , 0
);
SELECT throws_ok( '_test_this' , 23503 );
DEALLOCATE ALL;
SELECT diag_test_name( 'Empire planet mining setting record with NULL planet identifier' );
PREPARE _test_this AS
INSERT INTO emp.planet_mining_settings(
empire_id , planet_id ,
resource_name_id , emppmset_weight
) VALUES (
_get_emp_name( 'testUser1' ) , NULL ,
_get_string( 'testResource1' ) , 0
);
SELECT throws_ok( '_test_this' , 23502 );
DEALLOCATE ALL;
SELECT diag_test_name( 'Empire planet mining setting record with invalid planet identifier' );
PREPARE _test_this AS
INSERT INTO emp.planet_mining_settings(
empire_id , planet_id ,
resource_name_id , emppmset_weight
) VALUES (
_get_emp_name( 'testUser1' ) , _get_bad_map_name( ) ,
_get_string( 'testResource1' ) , 0
);
SELECT throws_ok( '_test_this' , 23503 );
DEALLOCATE ALL;
SELECT diag_test_name( 'Empire planet mining setting record with NULL resource identifier' );
PREPARE _test_this AS
INSERT INTO emp.planet_mining_settings(
empire_id , planet_id ,
resource_name_id , emppmset_weight
) VALUES (
_get_emp_name( 'testUser1' ) , _get_map_name( 'testPlanet2' ) ,
NULL , 0
);
SELECT throws_ok( '_test_this' , 23502 );
DEALLOCATE ALL;
SELECT diag_test_name( 'Empire planet mining setting record with invalid resource identifier' );
PREPARE _test_this AS
INSERT INTO emp.planet_mining_settings(
empire_id , planet_id ,
resource_name_id , emppmset_weight
) VALUES (
_get_emp_name( 'testUser1' ) , _get_map_name( 'testPlanet2' ) ,
_get_bad_string( ) , 0
);
SELECT throws_ok( '_test_this' , 23503 );
DEALLOCATE ALL;
SELECT diag_test_name( 'Empire planet mining setting record with invalid resource provider identifier' );
PREPARE _test_this AS
INSERT INTO emp.planet_mining_settings(
empire_id , planet_id ,
resource_name_id , emppmset_weight
) VALUES (
_get_emp_name( 'testUser1' ) , _get_map_name( 'testPlanet2' ) ,
_get_string( 'testResource2' ) , 0
);
SELECT throws_ok( '_test_this' , 23503 );
DEALLOCATE ALL;
SELECT diag_test_name( 'Empire planet mining setting record with NULL weight' );
PREPARE _test_this AS
INSERT INTO emp.planet_mining_settings(
empire_id , planet_id ,
resource_name_id , emppmset_weight
) VALUES (
_get_emp_name( 'testUser1' ) , _get_map_name( 'testPlanet1' ) ,
_get_string( 'testResource1' ) , NULL
);
SELECT throws_ok( '_test_this' , 23502 );
DEALLOCATE ALL;
SELECT diag_test_name( 'Empire planet mining setting record with weight < 0' );
PREPARE _test_this AS
INSERT INTO emp.planet_mining_settings(
empire_id , planet_id ,
resource_name_id , emppmset_weight
) VALUES (
_get_emp_name( 'testUser1' ) , _get_map_name( 'testPlanet1' ) ,
_get_string( 'testResource1' ) , -1
);
SELECT throws_ok( '_test_this' , 23514 );
DEALLOCATE ALL;
SELECT * FROM finish( );
ROLLBACK;