Emmanuel BENOîT
afc66166e0
* Changed the way mining settings work: use a priority value (between 0 and 4) as the weight. Leaving them as they were before would have caused numerous problems (and a lot of unnecessary code to work around them) * Empire mining settings will be created along with the empire's own record. By default all natural resources will have weight = 2. * Added a set of four stored procedures which can be used to update an empire's mining settings, including planet-specific settings. The emp.mset_update_start() function can be used to start an update (on an empire's settings if there is only one parameter, or on a planet's settings if there are two parameters); the emp.mset_update_set() and emp.mset_update_apply() functions are then used to modify the settings and apply the changes, respectively.
142 lines
No EOL
4.2 KiB
PL/PgSQL
142 lines
No EOL
4.2 KiB
PL/PgSQL
/*
|
|
* Test constraints and foreign keys on emp.mining_settings
|
|
*/
|
|
BEGIN;
|
|
|
|
/* We need to create a pair of resources and a pair of empires */
|
|
\i utils/strings.sql
|
|
\i utils/resources.sql
|
|
\i utils/accounts.sql
|
|
\i utils/naming.sql
|
|
SELECT _create_natural_resources( 2 , 'testResource' );
|
|
SELECT _create_emp_names( 2 , 'testUser' );
|
|
INSERT INTO emp.empires ( name_id , cash )
|
|
SELECT id , 0 FROM naming.empire_names;
|
|
|
|
/****** TESTS BEGIN HERE ******/
|
|
SELECT plan( 13 );
|
|
|
|
|
|
SELECT diag_test_name( 'emp.mining_settings - Valid record' );
|
|
PREPARE _test_this AS
|
|
INSERT INTO emp.mining_settings(
|
|
empire_id , resource_name_id , empmset_weight
|
|
) VALUES (
|
|
_get_emp_name( 'testUser1' ) , _get_string( 'testResource1' ) , 0
|
|
);
|
|
SELECT lives_ok( '_test_this' );
|
|
|
|
SELECT diag_test_name( 'emp.mining_settings - Duplicate record' );
|
|
SELECT throws_ok( '_test_this' , 23505 );
|
|
DEALLOCATE ALL;
|
|
|
|
SELECT diag_test_name( 'emp.mining_settings - Same empire, different types' );
|
|
PREPARE _test_this AS
|
|
INSERT INTO emp.mining_settings(
|
|
empire_id , resource_name_id , empmset_weight
|
|
) VALUES (
|
|
_get_emp_name( 'testUser1' ) , _get_string( 'testResource2' ) , 0
|
|
);
|
|
SELECT lives_ok( '_test_this' );
|
|
DEALLOCATE ALL;
|
|
|
|
SELECT diag_test_name( 'emp.mining_settings - Same type, different empires' );
|
|
PREPARE _test_this AS
|
|
INSERT INTO emp.mining_settings(
|
|
empire_id , resource_name_id , empmset_weight
|
|
) VALUES (
|
|
_get_emp_name( 'testUser2' ) , _get_string( 'testResource1' ) , 0
|
|
);
|
|
SELECT lives_ok( '_test_this' );
|
|
DEALLOCATE ALL;
|
|
DELETE FROM emp.mining_settings;
|
|
|
|
SELECT diag_test_name( 'emp.mining_settings - Valid record with default weight' );
|
|
PREPARE _test_this AS
|
|
INSERT INTO emp.mining_settings(
|
|
empire_id , resource_name_id
|
|
) VALUES (
|
|
_get_emp_name( 'testUser1' ) , _get_string( 'testResource1' )
|
|
);
|
|
SELECT lives_ok( '_test_this' );
|
|
DEALLOCATE ALL;
|
|
|
|
SELECT diag_test_name( 'emp.mining_settings - Default weight = 2' );
|
|
SELECT is( empmset_weight , 2 ) FROM emp.mining_settings;
|
|
DELETE FROM emp.mining_settings;
|
|
|
|
SELECT diag_test_name( 'emp.mining_settings - NULL empire identifier' );
|
|
PREPARE _test_this AS
|
|
INSERT INTO emp.mining_settings(
|
|
empire_id , resource_name_id , empmset_weight
|
|
) VALUES (
|
|
NULL , _get_string( 'testResource1' ) , 0
|
|
);
|
|
SELECT throws_ok( '_test_this' , 23502 );
|
|
DEALLOCATE ALL;
|
|
|
|
SELECT diag_test_name( 'emp.mining_settings - Invalid empire identifier' );
|
|
PREPARE _test_this AS
|
|
INSERT INTO emp.mining_settings(
|
|
empire_id , resource_name_id , empmset_weight
|
|
) VALUES (
|
|
_get_bad_emp_name( ) , _get_string( 'testResource1' ) , 0
|
|
);
|
|
SELECT throws_ok( '_test_this' , 23503 );
|
|
DEALLOCATE ALL;
|
|
|
|
|
|
SELECT diag_test_name( 'emp.mining_settings - NULL resource identifier' );
|
|
PREPARE _test_this AS
|
|
INSERT INTO emp.mining_settings(
|
|
empire_id , resource_name_id , empmset_weight
|
|
) VALUES (
|
|
_get_emp_name( 'testUser1' ) , NULL , 0
|
|
);
|
|
SELECT throws_ok( '_test_this' , 23502 );
|
|
DEALLOCATE ALL;
|
|
|
|
SELECT diag_test_name( 'emp.mining_settings - Invalid resource identifier' );
|
|
PREPARE _test_this AS
|
|
INSERT INTO emp.mining_settings(
|
|
empire_id , resource_name_id , empmset_weight
|
|
) VALUES (
|
|
_get_emp_name( 'testUser1' ) , _get_bad_string( ) , 0
|
|
);
|
|
SELECT throws_ok( '_test_this' , 23503 );
|
|
DEALLOCATE ALL;
|
|
|
|
|
|
SELECT diag_test_name( 'emp.mining_settings - NULL weight' );
|
|
PREPARE _test_this AS
|
|
INSERT INTO emp.mining_settings(
|
|
empire_id , resource_name_id , empmset_weight
|
|
) VALUES (
|
|
_get_emp_name( 'testUser1' ) , _get_string( 'testResource1' ) , NULL
|
|
);
|
|
SELECT throws_ok( '_test_this' , 23502 );
|
|
DEALLOCATE ALL;
|
|
|
|
SELECT diag_test_name( 'emp.mining_settings - Weight < 0' );
|
|
PREPARE _test_this AS
|
|
INSERT INTO emp.mining_settings(
|
|
empire_id , resource_name_id , empmset_weight
|
|
) VALUES (
|
|
_get_emp_name( 'testUser1' ) , _get_string( 'testResource1' ) , -1
|
|
);
|
|
SELECT throws_ok( '_test_this' , 23514 );
|
|
DEALLOCATE ALL;
|
|
|
|
SELECT diag_test_name( 'emp.mining_settings - Weight > 4' );
|
|
PREPARE _test_this AS
|
|
INSERT INTO emp.mining_settings(
|
|
empire_id , resource_name_id , empmset_weight
|
|
) VALUES (
|
|
_get_emp_name( 'testUser1' ) , _get_string( 'testResource1' ) , 5
|
|
);
|
|
SELECT throws_ok( '_test_this' , 23514 );
|
|
DEALLOCATE ALL;
|
|
|
|
|
|
SELECT * FROM finish( );
|
|
ROLLBACK; |