2012-01-10 13:29:56 +01:00
|
|
|
/*
|
|
|
|
* Test the sys.process_empire_resources_updates() function
|
|
|
|
*/
|
|
|
|
BEGIN;
|
2012-02-03 16:25:03 +01:00
|
|
|
/* Start by deleting all update types except for the one
|
|
|
|
* we're interested in.
|
|
|
|
*/
|
|
|
|
DELETE FROM sys.update_types
|
|
|
|
WHERE updtype_name <> 'EmpireResources';
|
|
|
|
|
2012-01-10 13:29:56 +01:00
|
|
|
/* We need:
|
|
|
|
* - three types of resources,
|
2012-02-16 10:22:30 +01:00
|
|
|
* - three empires with resources records, and the corresponding update
|
2012-01-10 13:29:56 +01:00
|
|
|
* record,
|
2012-02-16 10:22:30 +01:00
|
|
|
* - three planets, set to belong to the aforementioned empires, with
|
2012-01-10 13:29:56 +01:00
|
|
|
* resources records attached.
|
|
|
|
*/
|
|
|
|
\i utils/strings.sql
|
|
|
|
\i utils/resources.sql
|
|
|
|
\i utils/accounts.sql
|
|
|
|
\i utils/naming.sql
|
|
|
|
\i utils/universe.sql
|
|
|
|
SELECT _create_resources( 3 , 'testResource' );
|
2012-02-16 10:22:30 +01:00
|
|
|
SELECT _create_raw_planets( 3 , 'testPlanet' );
|
|
|
|
SELECT _create_emp_names( 3 , 'testEmp' );
|
2012-01-10 13:29:56 +01:00
|
|
|
INSERT INTO verse.planet_resources ( planet_id , resource_name_id )
|
|
|
|
SELECT _get_map_name( 'testPlanet1' ) , resource_name_id FROM defs.resources;
|
|
|
|
INSERT INTO verse.planet_resources ( planet_id , resource_name_id )
|
|
|
|
SELECT _get_map_name( 'testPlanet2' ) , resource_name_id FROM defs.resources;
|
2012-02-16 10:22:30 +01:00
|
|
|
INSERT INTO verse.planet_resources ( planet_id , resource_name_id )
|
|
|
|
SELECT _get_map_name( 'testPlanet3' ) , resource_name_id FROM defs.resources;
|
2012-01-10 13:29:56 +01:00
|
|
|
|
|
|
|
/* Set up the planets' resource records so that:
|
|
|
|
* - income > upkeep for testResource1 ,
|
|
|
|
* - income < upkeep for testResource2 ,
|
|
|
|
* - income = upkeep = 0 for testResource3 ,
|
|
|
|
*/
|
|
|
|
UPDATE verse.planet_resources SET pres_income = 12
|
|
|
|
WHERE resource_name_id = _get_string( 'testResource1' );
|
|
|
|
UPDATE verse.planet_resources SET pres_upkeep = 34
|
|
|
|
WHERE resource_name_id = _get_string( 'testResource2' );
|
|
|
|
|
2012-02-16 10:22:30 +01:00
|
|
|
/* Create testEmp1 empire */
|
|
|
|
SELECT emp.create_empire( _get_emp_name( 'testEmp1' ) , _get_map_name( 'testPlanet1' ) , 1 );
|
|
|
|
|
|
|
|
/* Create testEmp2 empire and add a vacation mode entry; also set the vacation.cashDivider constant */
|
|
|
|
SELECT emp.create_empire( _get_emp_name( 'testEmp2' ) , _get_map_name( 'testPlanet2' ) , 1 );
|
|
|
|
ALTER TABLE users.vacations
|
|
|
|
DROP CONSTRAINT fk_vacations_accounts;
|
|
|
|
INSERT INTO users.vacations ( account_id , since , status )
|
|
|
|
SELECT owner_id , now( ) , 'PROCESSED'
|
|
|
|
FROM naming.empire_names
|
|
|
|
WHERE id = _get_emp_name( 'testEmp2' );
|
|
|
|
SELECT sys.uoc_constant( 'vacation.cashDivider' , '(test)' , 'Resources' , 2 );
|
|
|
|
|
2012-01-10 13:29:56 +01:00
|
|
|
/* Make sure update 0 is set to be processed for testEmp1 */
|
|
|
|
UPDATE sys.updates
|
2012-02-03 16:25:03 +01:00
|
|
|
SET update_state = 'PROCESSING' , update_last = 0;
|
2012-01-10 13:29:56 +01:00
|
|
|
|
2012-02-16 10:22:30 +01:00
|
|
|
/* Create testEmp3 empire, make sure it will not be processed */
|
|
|
|
SELECT emp.create_empire( _get_emp_name( 'testEmp3' ) , _get_map_name( 'testPlanet3' ) , 1 );
|
2012-01-10 13:29:56 +01:00
|
|
|
UPDATE sys.updates _su
|
2012-02-03 16:25:03 +01:00
|
|
|
SET update_state = 'PROCESSED' , update_last = 0
|
|
|
|
FROM emp.empires_updates _eu
|
|
|
|
WHERE _eu.update_id = _su.update_id
|
2012-02-16 10:22:30 +01:00
|
|
|
AND _eu.name_id = _get_emp_name( 'testEmp3' );
|
2012-01-10 13:29:56 +01:00
|
|
|
|
|
|
|
/****** TESTS BEGIN HERE ******/
|
2012-02-16 10:22:30 +01:00
|
|
|
SELECT plan( 31 );
|
2012-01-10 13:29:56 +01:00
|
|
|
|
|
|
|
SELECT sys.process_empire_resources_updates( 10 );
|
|
|
|
SELECT diag_test_name( 'EMPIRE_RESOURCES update - Wrong update identifier (1/6)' );
|
|
|
|
SELECT is( empres_possessed , 0::DOUBLE PRECISION ) FROM emp.resources
|
|
|
|
WHERE resource_name_id = _get_string( 'testResource1' );
|
|
|
|
SELECT diag_test_name( 'EMPIRE_RESOURCES update - Wrong update identifier (2/6)' );
|
|
|
|
SELECT is( empres_owed , 0::DOUBLE PRECISION ) FROM emp.resources
|
|
|
|
WHERE resource_name_id = _get_string( 'testResource1' );
|
|
|
|
SELECT diag_test_name( 'EMPIRE_RESOURCES update - Wrong update identifier (3/6)' );
|
|
|
|
SELECT is( empres_possessed , 0::DOUBLE PRECISION ) FROM emp.resources
|
|
|
|
WHERE resource_name_id = _get_string( 'testResource2' );
|
|
|
|
SELECT diag_test_name( 'EMPIRE_RESOURCES update - Wrong update identifier (4/6)' );
|
|
|
|
SELECT is( empres_owed , 0::DOUBLE PRECISION ) FROM emp.resources
|
|
|
|
WHERE resource_name_id = _get_string( 'testResource2' );
|
|
|
|
SELECT diag_test_name( 'EMPIRE_RESOURCES update - Wrong update identifier (5/6)' );
|
|
|
|
SELECT is( empres_possessed , 0::DOUBLE PRECISION ) FROM emp.resources
|
|
|
|
WHERE resource_name_id = _get_string( 'testResource3' );
|
|
|
|
SELECT diag_test_name( 'EMPIRE_RESOURCES update - Wrong update identifier (6/6)' );
|
|
|
|
SELECT is( empres_owed , 0::DOUBLE PRECISION ) FROM emp.resources
|
|
|
|
WHERE resource_name_id = _get_string( 'testResource3' );
|
|
|
|
|
|
|
|
SELECT sys.process_empire_resources_updates( 0 );
|
2012-02-16 10:22:30 +01:00
|
|
|
|
2012-01-10 13:29:56 +01:00
|
|
|
SELECT diag_test_name( 'EMPIRE_RESOURCES update - Resource 1 - Possessed quantity increased' );
|
|
|
|
SELECT is( empres_possessed , 12::DOUBLE PRECISION ) FROM emp.resources
|
|
|
|
WHERE resource_name_id = _get_string( 'testResource1' )
|
|
|
|
AND empire_id = _get_emp_name( 'testEmp1' );
|
|
|
|
SELECT diag_test_name( 'EMPIRE_RESOURCES update - Resource 1 - Owed quantity unchanged' );
|
|
|
|
SELECT is( empres_owed , 0::DOUBLE PRECISION ) FROM emp.resources
|
|
|
|
WHERE resource_name_id = _get_string( 'testResource1' )
|
|
|
|
AND empire_id = _get_emp_name( 'testEmp1' );
|
|
|
|
SELECT diag_test_name( 'EMPIRE_RESOURCES update - Resource 2 - Possessed quantity unchanged' );
|
|
|
|
SELECT is( empres_possessed , 0::DOUBLE PRECISION ) FROM emp.resources
|
|
|
|
WHERE resource_name_id = _get_string( 'testResource2' )
|
|
|
|
AND empire_id = _get_emp_name( 'testEmp1' );
|
|
|
|
SELECT diag_test_name( 'EMPIRE_RESOURCES update - Resource 2 - Owed quantity increased' );
|
|
|
|
SELECT is( empres_owed , 34::DOUBLE PRECISION ) FROM emp.resources
|
|
|
|
WHERE resource_name_id = _get_string( 'testResource2' )
|
|
|
|
AND empire_id = _get_emp_name( 'testEmp1' );
|
|
|
|
SELECT diag_test_name( 'EMPIRE_RESOURCES update - Resource 3 - Possessed quantity unchanged' );
|
|
|
|
SELECT is( empres_possessed , 0::DOUBLE PRECISION ) FROM emp.resources
|
|
|
|
WHERE resource_name_id = _get_string( 'testResource3' )
|
|
|
|
AND empire_id = _get_emp_name( 'testEmp1' );
|
|
|
|
SELECT diag_test_name( 'EMPIRE_RESOURCES update - Resource 3 - Owed quantity unchanged' );
|
|
|
|
SELECT is( empres_owed , 0::DOUBLE PRECISION ) FROM emp.resources
|
|
|
|
WHERE resource_name_id = _get_string( 'testResource3' )
|
|
|
|
AND empire_id = _get_emp_name( 'testEmp1' );
|
2012-02-16 10:22:30 +01:00
|
|
|
|
|
|
|
SELECT diag_test_name( 'EMPIRE_RESOURCES update - Resource 1 / Vacation - Possessed quantity increased' );
|
|
|
|
SELECT is( empres_possessed , 6::DOUBLE PRECISION ) FROM emp.resources
|
|
|
|
WHERE resource_name_id = _get_string( 'testResource1' )
|
|
|
|
AND empire_id = _get_emp_name( 'testEmp2' );
|
|
|
|
SELECT diag_test_name( 'EMPIRE_RESOURCES update - Resource 1 / Vacation - Owed quantity unchanged' );
|
|
|
|
SELECT is( empres_owed , 0::DOUBLE PRECISION ) FROM emp.resources
|
|
|
|
WHERE resource_name_id = _get_string( 'testResource1' )
|
|
|
|
AND empire_id = _get_emp_name( 'testEmp2' );
|
|
|
|
SELECT diag_test_name( 'EMPIRE_RESOURCES update - Resource 2 / Vacation - Possessed quantity unchanged' );
|
|
|
|
SELECT is( empres_possessed , 0::DOUBLE PRECISION ) FROM emp.resources
|
|
|
|
WHERE resource_name_id = _get_string( 'testResource2' )
|
|
|
|
AND empire_id = _get_emp_name( 'testEmp2' );
|
|
|
|
SELECT diag_test_name( 'EMPIRE_RESOURCES update - Resource 2 / Vacation - Owed quantity increased' );
|
|
|
|
SELECT is( empres_owed , 17::DOUBLE PRECISION ) FROM emp.resources
|
|
|
|
WHERE resource_name_id = _get_string( 'testResource2' )
|
|
|
|
AND empire_id = _get_emp_name( 'testEmp2' );
|
|
|
|
SELECT diag_test_name( 'EMPIRE_RESOURCES update - Resource 3 / Vacation - Possessed quantity unchanged' );
|
|
|
|
SELECT is( empres_possessed , 0::DOUBLE PRECISION ) FROM emp.resources
|
|
|
|
WHERE resource_name_id = _get_string( 'testResource3' )
|
|
|
|
AND empire_id = _get_emp_name( 'testEmp2' );
|
|
|
|
SELECT diag_test_name( 'EMPIRE_RESOURCES update - Resource 3 / Vacation - Owed quantity unchanged' );
|
|
|
|
SELECT is( empres_owed , 0::DOUBLE PRECISION ) FROM emp.resources
|
|
|
|
WHERE resource_name_id = _get_string( 'testResource3' )
|
|
|
|
AND empire_id = _get_emp_name( 'testEmp2' );
|
|
|
|
|
2012-01-10 13:29:56 +01:00
|
|
|
SELECT diag_test_name( 'EMPIRE_RESOURCES update - Resources unchanged for already processed empire' );
|
|
|
|
SELECT is( SUM( empres_owed + empres_possessed ) , 0::DOUBLE PRECISION )
|
|
|
|
FROM emp.resources
|
2012-02-16 10:22:30 +01:00
|
|
|
WHERE empire_id = _get_emp_name( 'testEmp3' );
|
2012-01-10 13:29:56 +01:00
|
|
|
|
|
|
|
SELECT * FROM finish( );
|
|
|
|
ROLLBACK;
|