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/050-updates/105-planet-resource-regeneration/010-process-planet-res-regen-updates.sql
Emmanuel BENOîT e50775ec76 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
2012-01-06 11:19:19 +01:00

87 lines
No EOL
3.2 KiB
PL/PgSQL

/*
* Test for the sys.process_planet_res_regen_updates() function
*/
BEGIN;
/* We need to create a natural resource 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( 1 , 'testResource' );
SELECT _create_raw_planets( 3 , 'testPlanet' );
/* Define the necessary constants using default values */
SELECT sys.uoc_constant( 'game.resources.recovery' , '(test)' , 'Resources' , 0.01 );
SELECT sys.uoc_constant( 'game.resources.recoveryDampening' , '(test)' , 'Resources' , 1.5 );
/* Create resource providers */
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
) , (
_get_map_name( 'testPlanet2' ) , _get_string( 'testResource1' ) ,
100 , 100 ,
0.5 , 0.5
) , (
_get_map_name( 'testPlanet3' ) , _get_string( 'testResource1' ) ,
100 , 50 ,
0.5 , 0.5
);
/* Insert update records for the planets. Planets 1 and 2 will be processed,
* planet testPlanet3 will not.
*/
INSERT INTO sys.updates ( id , gu_type , status , last_tick )
VALUES ( 1 , 'PLANET_RES_REGEN' , 'PROCESSING' , 0 );
INSERT INTO verse.updates ( update_id , planet_id )
VALUES ( 1 , _get_map_name( 'testPlanet1' ) );
INSERT INTO sys.updates ( id , gu_type , status , last_tick )
VALUES ( 2 , 'PLANET_RES_REGEN' , 'PROCESSING' , 0 );
INSERT INTO verse.updates ( update_id , planet_id )
VALUES ( 2 , _get_map_name( 'testPlanet2' ) );
INSERT INTO sys.updates ( id , gu_type , status , last_tick )
VALUES ( 3 , 'PLANET_RES_REGEN' , 'PROCESSED' , 0 );
INSERT INTO verse.updates ( update_id , planet_id )
VALUES ( 3 , _get_map_name( 'testPlanet3' ) );
/* Helper function that gets a provider's current quantity */
CREATE FUNCTION _get_quantity( _planet TEXT )
RETURNS DOUBLE PRECISION
AS $$
SELECT resprov_quantity FROM verse.resource_providers
WHERE planet_id = _get_map_name( $1 )
AND resource_name_id = _get_string( 'testResource1' );
$$ LANGUAGE SQL;
/****** TESTS BEGIN HERE ******/
SELECT plan( 6 );
SELECT sys.process_planet_res_regen_updates( 10 );
SELECT diag_test_name( 'PLANET_RES_REGEN update - Wrong update identifier (1/3)' );
SELECT ok( _get_quantity( 'testPlanet1' ) = 50 );
SELECT diag_test_name( 'PLANET_RES_REGEN update - Wrong update identifier (2/3)' );
SELECT ok( _get_quantity( 'testPlanet2' ) = 100 );
SELECT diag_test_name( 'PLANET_RES_REGEN update - Wrong update identifier (3/3)' );
SELECT ok( _get_quantity( 'testPlanet3' ) = 50 );
SELECT sys.process_planet_res_regen_updates( 0 );
SELECT diag_test_name( 'PLANET_RES_REGEN update - Processed planet with quantity < max.' );
SELECT ok( _get_quantity( 'testPlanet1' ) > 50 );
SELECT diag_test_name( 'PLANET_RES_REGEN update - Processed planet with quantity = max.' );
SELECT ok( _get_quantity( 'testPlanet2' ) = 100 );
SELECT diag_test_name( 'PLANET_RES_REGEN update - Already processed planet' );
SELECT ok( _get_quantity( 'testPlanet3' ) = 50 );
SELECT * FROM finish( );
ROLLBACK;