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/100-universe

View file

@ -0,0 +1,331 @@
/*
* Test constraints and foreign keys on verse.resource_providers
*/
BEGIN;
/* We need a pair of resource definitions and a pair of planets. */
\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_raw_planets( 2 , 'testPlanet' );
/****** TESTS BEGIN HERE ******/
SELECT plan( 22 );
SELECT diag_test_name( 'Valid resource provider' );
PREPARE _test_this AS
INSERT INTO verse.resource_providers(
planet_id , resource_name_id ,
resprov_quantity_max , resprov_quantity ,
resprov_difficulty , resprov_recovery
) VALUES (
_get_map_name( 'testPlanet1' ) , _get_string( 'testResource1' ) ,
100 , 50 ,
0.5 , 0.5
);
SELECT lives_ok( '_test_this' );
SELECT diag_test_name( 'Duplicate resource provider' );
SELECT throws_ok( '_test_this' , 23505 );
DEALLOCATE ALL;
SELECT diag_test_name( 'Resource provider with same planet but different type' );
PREPARE _test_this AS
INSERT INTO verse.resource_providers(
planet_id , resource_name_id ,
resprov_quantity_max , resprov_quantity ,
resprov_difficulty , resprov_recovery
) VALUES (
_get_map_name( 'testPlanet1' ) , _get_string( 'testResource2' ) ,
100 , 50 ,
0.5 , 0.5
);
SELECT lives_ok( '_test_this' );
DEALLOCATE ALL;
SELECT diag_test_name( 'Resource provider with same type but different planet' );
PREPARE _test_this AS
INSERT INTO verse.resource_providers(
planet_id , resource_name_id ,
resprov_quantity_max , resprov_quantity ,
resprov_difficulty , resprov_recovery
) VALUES (
_get_map_name( 'testPlanet2' ) , _get_string( 'testResource1' ) ,
100 , 50 ,
0.5 , 0.5
);
SELECT lives_ok( '_test_this' );
DEALLOCATE ALL;
DELETE FROM verse.resource_providers;
SELECT diag_test_name( 'Resource provider with NULL planet identifier' );
PREPARE _test_this AS
INSERT INTO verse.resource_providers(
planet_id , resource_name_id ,
resprov_quantity_max , resprov_quantity ,
resprov_difficulty , resprov_recovery
) VALUES (
NULL , _get_string( 'testResource1' ) ,
100 , 50 ,
0.5 , 0.5
);
SELECT throws_ok( '_test_this' , 23502 );
DEALLOCATE ALL;
SELECT diag_test_name( 'Resource provider with invalid planet identifier' );
PREPARE _test_this AS
INSERT INTO verse.resource_providers(
planet_id , resource_name_id ,
resprov_quantity_max , resprov_quantity ,
resprov_difficulty , resprov_recovery
) VALUES (
_get_bad_map_name( ) , _get_string( 'testResource1' ) ,
100 , 50 ,
0.5 , 0.5
);
SELECT throws_ok( '_test_this' , 23503 );
DEALLOCATE ALL;
SELECT diag_test_name( 'Resource provider with NULL resource identifier' );
PREPARE _test_this AS
INSERT INTO verse.resource_providers(
planet_id , resource_name_id ,
resprov_quantity_max , resprov_quantity ,
resprov_difficulty , resprov_recovery
) VALUES (
_get_map_name( 'testPlanet1' ) , NULL ,
100 , 50 ,
0.5 , 0.5
);
SELECT throws_ok( '_test_this' , 23502 );
DEALLOCATE ALL;
SELECT diag_test_name( 'Resource provider with invalid resource identifier' );
PREPARE _test_this AS
INSERT INTO verse.resource_providers(
planet_id , resource_name_id ,
resprov_quantity_max , resprov_quantity ,
resprov_difficulty , resprov_recovery
) VALUES (
_get_map_name( 'testPlanet1' ) , _get_bad_string( ) ,
100 , 50 ,
0.5 , 0.5
);
SELECT throws_ok( '_test_this' , 23503 );
DEALLOCATE ALL;
SELECT diag_test_name( 'Resource provider with NULL maximal quantity' );
PREPARE _test_this AS
INSERT INTO verse.resource_providers(
planet_id , resource_name_id ,
resprov_quantity_max , resprov_quantity ,
resprov_difficulty , resprov_recovery
) VALUES (
_get_map_name( 'testPlanet1' ) , _get_string( 'testResource1' ) ,
NULL , 50 ,
0.5 , 0.5
);
SELECT throws_ok( '_test_this' , 23502 );
DEALLOCATE ALL;
SELECT diag_test_name( 'Resource provider with maximal quantity <= 0' );
PREPARE _test_this AS
INSERT INTO verse.resource_providers(
planet_id , resource_name_id ,
resprov_quantity_max , resprov_quantity ,
resprov_difficulty , resprov_recovery
) VALUES (
_get_map_name( 'testPlanet1' ) , _get_string( 'testResource1' ) ,
0 , 0 ,
0.5 , 0.5
);
SELECT throws_ok( '_test_this' , 23514 );
DEALLOCATE ALL;
SELECT diag_test_name( 'Resource provider with NULL quantity' );
PREPARE _test_this AS
INSERT INTO verse.resource_providers(
planet_id , resource_name_id ,
resprov_quantity_max , resprov_quantity ,
resprov_difficulty , resprov_recovery
) VALUES (
_get_map_name( 'testPlanet1' ) , _get_string( 'testResource1' ) ,
100 , NULL ,
0.5 , 0.5
);
SELECT throws_ok( '_test_this' , 23502 );
DEALLOCATE ALL;
SELECT diag_test_name( 'Resource provider with quantity < 0' );
PREPARE _test_this AS
INSERT INTO verse.resource_providers(
planet_id , resource_name_id ,
resprov_quantity_max , resprov_quantity ,
resprov_difficulty , resprov_recovery
) VALUES (
_get_map_name( 'testPlanet1' ) , _get_string( 'testResource1' ) ,
100 , -1 ,
0.5 , 0.5
);
SELECT throws_ok( '_test_this' , 23514 );
DEALLOCATE ALL;
SELECT diag_test_name( 'Resource provider with quantity > max. quantity' );
PREPARE _test_this AS
INSERT INTO verse.resource_providers(
planet_id , resource_name_id ,
resprov_quantity_max , resprov_quantity ,
resprov_difficulty , resprov_recovery
) VALUES (
_get_map_name( 'testPlanet1' ) , _get_string( 'testResource1' ) ,
100 , 101 ,
0.5 , 0.5
);
SELECT throws_ok( '_test_this' , 23514 );
DEALLOCATE ALL;
SELECT diag_test_name( 'Resource provider with NULL difficulty' );
PREPARE _test_this AS
INSERT INTO verse.resource_providers(
planet_id , resource_name_id ,
resprov_quantity_max , resprov_quantity ,
resprov_difficulty , resprov_recovery
) VALUES (
_get_map_name( 'testPlanet1' ) , _get_string( 'testResource1' ) ,
100 , 50 ,
NULL , 0.5
);
SELECT throws_ok( '_test_this' , 23502 );
DEALLOCATE ALL;
SELECT diag_test_name( 'Resource provider with difficulty < 0' );
PREPARE _test_this AS
INSERT INTO verse.resource_providers(
planet_id , resource_name_id ,
resprov_quantity_max , resprov_quantity ,
resprov_difficulty , resprov_recovery
) VALUES (
_get_map_name( 'testPlanet1' ) , _get_string( 'testResource1' ) ,
100 , 50 ,
-0.5 , 0.5
);
SELECT throws_ok( '_test_this' , 23514 );
DEALLOCATE ALL;
SELECT diag_test_name( 'Resource provider with difficulty > 1' );
PREPARE _test_this AS
INSERT INTO verse.resource_providers(
planet_id , resource_name_id ,
resprov_quantity_max , resprov_quantity ,
resprov_difficulty , resprov_recovery
) VALUES (
_get_map_name( 'testPlanet1' ) , _get_string( 'testResource1' ) ,
100 , 50 ,
1.5 , 0.5
);
SELECT throws_ok( '_test_this' , 23514 );
DEALLOCATE ALL;
SELECT diag_test_name( 'Resource provider with difficulty = 0' );
PREPARE _test_this AS
INSERT INTO verse.resource_providers(
planet_id , resource_name_id ,
resprov_quantity_max , resprov_quantity ,
resprov_difficulty , resprov_recovery
) VALUES (
_get_map_name( 'testPlanet1' ) , _get_string( 'testResource1' ) ,
100 , 50 ,
0 , 0.5
);
SELECT lives_ok( '_test_this' );
DEALLOCATE ALL;
DELETE FROM verse.resource_providers;
SELECT diag_test_name( 'Resource provider with difficulty = 1' );
PREPARE _test_this AS
INSERT INTO verse.resource_providers(
planet_id , resource_name_id ,
resprov_quantity_max , resprov_quantity ,
resprov_difficulty , resprov_recovery
) VALUES (
_get_map_name( 'testPlanet1' ) , _get_string( 'testResource1' ) ,
100 , 50 ,
1 , 0.5
);
SELECT lives_ok( '_test_this' );
DEALLOCATE ALL;
DELETE FROM verse.resource_providers;
SELECT diag_test_name( 'Resource provider with NULL recovery' );
PREPARE _test_this AS
INSERT INTO verse.resource_providers(
planet_id , resource_name_id ,
resprov_quantity_max , resprov_quantity ,
resprov_difficulty , resprov_recovery
) VALUES (
_get_map_name( 'testPlanet1' ) , _get_string( 'testResource1' ) ,
100 , 50 ,
0.5 , NULL
);
SELECT throws_ok( '_test_this' , 23502 );
DEALLOCATE ALL;
SELECT diag_test_name( 'Resource provider with recovery = 0' );
PREPARE _test_this AS
INSERT INTO verse.resource_providers(
planet_id , resource_name_id ,
resprov_quantity_max , resprov_quantity ,
resprov_difficulty , resprov_recovery
) VALUES (
_get_map_name( 'testPlanet1' ) , _get_string( 'testResource1' ) ,
100 , 50 ,
0.5 , 0
);
SELECT throws_ok( '_test_this' , 23514 );
DEALLOCATE ALL;
SELECT diag_test_name( 'Resource provider with recovery > 1' );
PREPARE _test_this AS
INSERT INTO verse.resource_providers(
planet_id , resource_name_id ,
resprov_quantity_max , resprov_quantity ,
resprov_difficulty , resprov_recovery
) VALUES (
_get_map_name( 'testPlanet1' ) , _get_string( 'testResource1' ) ,
100 , 50 ,
0.5 , 1.5
);
SELECT throws_ok( '_test_this' , 23514 );
DEALLOCATE ALL;
SELECT diag_test_name( 'Resource provider with recovery = 1' );
PREPARE _test_this AS
INSERT INTO verse.resource_providers(
planet_id , resource_name_id ,
resprov_quantity_max , resprov_quantity ,
resprov_difficulty , resprov_recovery
) VALUES (
_get_map_name( 'testPlanet1' ) , _get_string( 'testResource1' ) ,
100 , 50 ,
0.5 , 1
);
SELECT lives_ok( '_test_this' );
DEALLOCATE ALL;
DELETE FROM verse.resource_providers;
SELECT * FROM finish( );
ROLLBACK;