2012-01-10 10:17:47 +01:00
|
|
|
/*
|
|
|
|
* Test the emp.mset_update_apply() function
|
|
|
|
*/
|
|
|
|
BEGIN;
|
|
|
|
/*
|
|
|
|
* Remove foreign keys from the empire mining settings table, insert some
|
|
|
|
* data into it.
|
|
|
|
*/
|
|
|
|
ALTER TABLE emp.mining_settings
|
|
|
|
DROP CONSTRAINT fk_empmset_empire ,
|
|
|
|
DROP CONSTRAINT fk_empmset_resource;
|
|
|
|
INSERT INTO emp.mining_settings ( empire_id , resource_name_id )
|
|
|
|
VALUES ( 1 , 1 ) , ( 1 , 2 );
|
|
|
|
|
|
|
|
/* Create the temporary table */
|
|
|
|
CREATE TEMPORARY TABLE mset_update(
|
|
|
|
empire_id INT ,
|
|
|
|
resource_name_id INT ,
|
|
|
|
empmset_weight INT
|
|
|
|
) ON COMMIT DROP;
|
|
|
|
INSERT INTO mset_update VALUES ( 1 , 1 , 0 ) , ( 1 , 2 , 4 );
|
|
|
|
|
|
|
|
/***** TESTS BEGIN HERE *****/
|
2012-01-31 12:14:38 +01:00
|
|
|
SELECT plan( 8 );
|
2012-01-10 10:17:47 +01:00
|
|
|
|
|
|
|
SELECT diag_test_name( 'emp.mset_update_apply() - Applying valid empire update' );
|
|
|
|
SELECT ok( emp.mset_update_apply( ) );
|
|
|
|
SELECT diag_test_name( 'emp.mset_update_apply() - Empire update results' );
|
|
|
|
SELECT set_eq(
|
|
|
|
$$ SELECT resource_name_id , empmset_weight FROM emp.mining_settings $$ ,
|
|
|
|
$$ VALUES ( 1 , 0 ) , ( 2 , 4 ) $$
|
|
|
|
);
|
|
|
|
|
|
|
|
/* Reset temporary table and settings */
|
|
|
|
DELETE FROM mset_update;
|
|
|
|
DELETE FROM emp.mining_settings;
|
|
|
|
INSERT INTO emp.mining_settings ( empire_id , resource_name_id )
|
|
|
|
VALUES ( 1 , 1 ) , ( 1 , 2 );
|
|
|
|
|
|
|
|
INSERT INTO mset_update VALUES ( 1 , 1 , -1 ) , ( 1 , 2 , 4 );
|
|
|
|
SELECT diag_test_name( 'emp.mset_update_apply() - Applying invalid empire update' );
|
|
|
|
SELECT ok( NOT emp.mset_update_apply( ) );
|
|
|
|
SELECT diag_test_name( 'emp.mset_update_apply() - Invalid empire update results' );
|
|
|
|
SELECT set_eq(
|
|
|
|
$$ SELECT resource_name_id , empmset_weight FROM emp.mining_settings $$ ,
|
|
|
|
$$ VALUES ( 1 , 2 ) , ( 2 , 2 ) $$
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
/* Re-create the temporary table to store planet mining settings, remove
|
|
|
|
* constraints from the planet mining settings table, insert data into
|
|
|
|
* both.
|
|
|
|
*/
|
|
|
|
ALTER TABLE emp.planet_mining_settings
|
|
|
|
DROP CONSTRAINT fk_emppmset_empire ,
|
|
|
|
DROP CONSTRAINT fk_emppmset_resource;
|
|
|
|
INSERT INTO emp.planet_mining_settings ( empire_id , planet_id , resource_name_id )
|
|
|
|
VALUES ( 1 , 1 , 1 ) , ( 1 , 1 , 2 );
|
|
|
|
|
|
|
|
DROP TABLE mset_update;
|
|
|
|
CREATE TEMPORARY TABLE mset_update(
|
|
|
|
empire_id INT ,
|
|
|
|
planet_id INT ,
|
|
|
|
resource_name_id INT ,
|
|
|
|
empmset_weight INT
|
|
|
|
) ON COMMIT DROP;
|
|
|
|
INSERT INTO mset_update VALUES ( 1 , 1 , 1 , 0 ) , ( 1 , 1 , 2 , 4 );
|
|
|
|
|
|
|
|
SELECT diag_test_name( 'emp.mset_update_apply() - Applying valid planet update' );
|
|
|
|
SELECT ok( emp.mset_update_apply( ) );
|
|
|
|
SELECT diag_test_name( 'emp.mset_update_apply() - Planet update results' );
|
|
|
|
SELECT set_eq(
|
|
|
|
$$ SELECT resource_name_id , emppmset_weight FROM emp.planet_mining_settings $$ ,
|
|
|
|
$$ VALUES ( 1 , 0 ) , ( 2 , 4 ) $$
|
|
|
|
);
|
|
|
|
|
|
|
|
/* Reset temporary table and settings */
|
|
|
|
DELETE FROM mset_update;
|
|
|
|
DELETE FROM emp.planet_mining_settings;
|
|
|
|
INSERT INTO emp.planet_mining_settings ( empire_id , planet_id , resource_name_id )
|
|
|
|
VALUES ( 1 , 1 , 1 ) , ( 1 , 1 , 2 );
|
|
|
|
|
|
|
|
INSERT INTO mset_update VALUES ( 1 , 1 , 1 , -1 ) , ( 1 , 1 , 2 , 4 );
|
|
|
|
SELECT diag_test_name( 'emp.mset_update_apply() - Applying invalid planet update' );
|
|
|
|
SELECT ok( NOT emp.mset_update_apply( ) );
|
|
|
|
SELECT diag_test_name( 'emp.mset_update_apply() - Invalid planet update results' );
|
|
|
|
SELECT set_eq(
|
|
|
|
$$ SELECT resource_name_id , emppmset_weight FROM emp.planet_mining_settings $$ ,
|
|
|
|
$$ VALUES ( 1 , 2 ) , ( 2 , 2 ) $$
|
|
|
|
);
|
|
|
|
|
|
|
|
SELECT * FROM finish( );
|
2012-01-31 12:14:38 +01:00
|
|
|
ROLLBACK;
|