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/120-planet-mining/050-process-planet-mining-updates.sql
Emmanuel BENOîT ba6a1e2b41 SQL unit tests fixes
* Added plan() instead of no_plan() where necessary

* Removed junk from dirty tests system self-check
2012-01-31 12:14:38 +01:00

58 lines
1.7 KiB
PL/PgSQL

/*
* Test the sys.process_planet_mining_updates() function
*/
BEGIN;
/*
* Create a fake planet resource record which will be updated by the
* function (dropping the foreign key is therefore needed).
*/
ALTER TABLE verse.planet_resources
DROP CONSTRAINT fk_pres_planet ,
DROP CONSTRAINT fk_pres_resource;
INSERT INTO verse.planet_resources(
planet_id , resource_name_id , pres_income , pres_upkeep
) VALUES (
1 , 1 , 42 , 0
);
/*
* Create a table which contains the values which will be returned by
* the fake sys.gu_pmc_get_data( ).
*/
CREATE TABLE _fake_update_data OF sys.gu_pmc_data_type;
INSERT INTO _fake_update_data VALUES (
1 , 1 , 1000.0 , 1000.0 , 0.5 , NULL , NULL , NULL , NULL ) ,
( 2 , 1 , 1000.0 , 1000.0 , 0.5 , 1 , 0.5 , 1.0 , 1.0 );
CREATE OR REPLACE FUNCTION sys.gu_pmc_get_data( _tick BIGINT )
RETURNS SETOF sys.gu_pmc_data_type
AS $$
SELECT * FROM _fake_update_data;
$$ LANGUAGE SQL;
/*
* Replace sys.gu_pmc_update_resource() so it deletes records from the
* table.
*/
CREATE OR REPLACE FUNCTION sys.gu_pmc_update_resource( _input sys.gu_pmc_data_type )
RETURNS VOID
AS $$
DELETE FROM _fake_update_data WHERE planet = $1.planet AND resource = $1.resource;
$$ LANGUAGE SQL;
/***** TESTS BEGIN HERE *****/
SELECT plan( 2 );
SELECT sys.process_planet_mining_updates( 0 );
SELECT diag_test_name( 'sys.process_planet_mining_updates() - Neutral planets updated' );
SELECT is( pres_income , 0::DOUBLE PRECISION ) FROM verse.planet_resources;
SELECT diag_test_name( 'sys.process_planet_mining_updates() - Owned planets updated' );
SELECT is_empty(
$$ SELECT * FROM _fake_update_data WHERE planet = 2 $$
);
SELECT * FROM finish( );
ROLLBACK;