/* * Test the emp.mset_toggle_source( INT , INT ) function */ BEGIN; /* * Create a pair of natural resources, three planets, an empire owning two * of the planets, and resource providers for one of the resources on the * neutral planet and on one of the owned 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( 2 , 'resource' ); SELECT _create_raw_planets( 3 , 'planet' ); SELECT _create_emp_names( 1 , 'empire' ); SELECT emp.create_empire( _get_emp_name( 'empire1' ) , _get_map_name( 'planet1' ) , 200.0 ); SELECT _create_resource_provider( 'planet1' , 'resource1' ); SELECT _create_resource_provider( 'planet2' , 'resource1' ); INSERT INTO emp.planets ( empire_id , planet_id ) VALUES ( _get_emp_name( 'empire1' ) , _get_map_name( 'planet3' ) ); -- ***** TESTS BEGIN HERE ***** SELECT plan( 8 ); SELECT diag_test_name( 'emp.mset_toggle_source() - Return value on bad empire identifier' ); SELECT ok( NOT emp.mset_toggle_source( _get_bad_emp_name( ) , _get_map_name( 'planet1' ) ) ); SELECT diag_test_name( 'emp.mset_toggle_source() - Return value on bad planbet identifier' ); SELECT ok( NOT emp.mset_toggle_source( _get_emp_name( 'empire1' ) , _get_bad_map_name( ) ) ); SELECT diag_test_name( 'emp.mset_toggle_source() - Return value when the empire does not own the planet' ); SELECT ok( NOT emp.mset_toggle_source( _get_emp_name( 'empire1' ) , _get_map_name( 'planet2' ) ) ); SELECT diag_test_name( 'emp.mset_toggle_source() - Return value when the planet has no resource providers' ); SELECT ok( NOT emp.mset_toggle_source( _get_emp_name( 'empire1' ) , _get_map_name( 'planet3' ) ) ); DELETE FROM emp.planet_mining_settings; UPDATE emp.mining_settings SET empmset_weight = 0; SELECT diag_test_name( 'emp.mset_toggle_source() - Return value when activating' ); SELECT ok( emp.mset_toggle_source( _get_emp_name( 'empire1' ) , _get_map_name( 'planet1' ) ) ); SELECT diag_test_name( 'emp.mset_toggle_source() - Mining settings inserted after activation' ); SELECT set_eq( $$ SELECT * FROM emp.planet_mining_settings $$ , $$ VALUES ( _get_emp_name( 'empire1' ) , _get_map_name( 'planet1' ) , _get_string( 'resource1' ) , 0 ) $$ ); DELETE FROM emp.planet_mining_settings; INSERT INTO emp.planet_mining_settings VALUES ( _get_emp_name( 'empire1' ) , _get_map_name( 'planet1' ) , _get_string( 'resource1' ) , 2 ); SELECT diag_test_name( 'emp.mset_toggle_source() - Return value when de-activating' ); SELECT ok( emp.mset_toggle_source( _get_emp_name( 'empire1' ) , _get_map_name( 'planet1' ) ) ); SELECT diag_test_name( 'emp.mset_toggle_source() - Mining settings deleted after de-activation' ); SELECT is_empty( $$ SELECT * FROM emp.planet_mining_settings $$ ); SELECT * FROM finish( ); ROLLBACK;