This repository has been archived on 2025-01-04. You can view files and clone it, but cannot push or open issues or pull requests.
lwb6/legacyworlds-server-data/db-structure/tests/admin/constraints/defs/10003-resource-providers.sql
Emmanuel BENOîT 4e1bb91780 Resource database structures
* Added structures for resource definitions, natural resources
definitions, resource providers, empire resources and empire mining
settings (both empire-wide and planet-specific).

* Added a few common utility functions to the SQL test suite. These
functions allow test initialisation to be a little shorter.

* Added "MINE" production type and an associated building definition.
The production will not be added to the XML dump or to the output of the
planets summary page, as this is extremely temporary.
2011-12-19 11:57:08 +01:00

331 lines
No EOL
9.4 KiB
PL/PgSQL

/*
* 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;