/* * Tests for bugs.dump_planet_resources_view */ BEGIN; /* * We need a couple of resources (one natural, one basic), four planets * with valid planet resource records (three of the planets will have a * resource provider and one of them will have planet-specific mining * settings), three empires (owning a planet without resource provider, * with resource provider and with resource provider and mining settings, * respectively). */ \i utils/strings.sql \i utils/resources.sql \i utils/accounts.sql \i utils/naming.sql \i utils/universe.sql SELECT _create_natural_resources( 1 , 'natRes' ); SELECT _create_resources( 1 , 'basicRes' ); SELECT _create_raw_planets( 4 , 'planet' ); INSERT INTO verse.planet_resources( planet_id , resource_name_id , pres_income , pres_upkeep ) VALUES ( _get_map_name( 'planet1' ) , _get_string( 'basicRes1' ) , 1 , 2 ) , ( _get_map_name( 'planet1' ) , _get_string( 'natRes1' ) , 3 , 4 ) , ( _get_map_name( 'planet2' ) , _get_string( 'basicRes1' ) , 5 , 6 ) , ( _get_map_name( 'planet2' ) , _get_string( 'natRes1' ) , 7 , 8 ) , ( _get_map_name( 'planet3' ) , _get_string( 'basicRes1' ) , 9 , 10 ) , ( _get_map_name( 'planet3' ) , _get_string( 'natRes1' ) , 11 , 12 ) , ( _get_map_name( 'planet4' ) , _get_string( 'basicRes1' ) , 13 , 14 ) , ( _get_map_name( 'planet4' ) , _get_string( 'natRes1' ) , 15 , 16 ); SELECT _create_resource_provider( 'planet1' , 'natRes1' ); SELECT _create_resource_provider( 'planet3' , 'natRes1' ); SELECT _create_resource_provider( 'planet4' , 'natRes1' ); SELECT _create_emp_names( 3 , 'empire' ); SELECT emp.create_empire( _get_emp_name( 'empire1' ) , _get_map_name( 'planet1' ) , 200.0 ); SELECT emp.create_empire( _get_emp_name( 'empire2' ) , _get_map_name( 'planet2' ) , 200.0 ); SELECT emp.create_empire( _get_emp_name( 'empire3' ) , _get_map_name( 'planet4' ) , 200.0 ); INSERT INTO emp.planet_mining_settings( empire_id , planet_id , resource_name_id , emppmset_weight ) VALUES ( _get_emp_name( 'empire3' ) , _get_map_name( 'planet4' ) , _get_string( 'natRes1' ) , 2 ); /***** TESTS BEGIN HERE *****/ SELECT plan( 3 ); SELECT diag_test_name( 'bugs.dump_planet_resources_view - Records without resource providers' ); SELECT set_eq( $$ SELECT empire_id , planet_id , resource_name , pres_income , pres_upkeep FROM bugs.dump_planet_resources_view WHERE resprov_quantity IS NULL $$ , $$ VALUES ( _get_emp_name( 'empire1' ) , _get_map_name( 'planet1' ) , 'basicRes1' , 1 , 2 ) , ( _get_emp_name( 'empire2' ) , _get_map_name( 'planet2' ) , 'basicRes1' , 5 , 6 ) , ( _get_emp_name( 'empire2' ) , _get_map_name( 'planet2' ) , 'natRes1' , 7 , 8 ) , ( _get_emp_name( 'empire3' ) , _get_map_name( 'planet4' ) , 'basicRes1' , 13 , 14 ) $$ ); SELECT diag_test_name( 'bugs.dump_planet_resources_view - Records with resource providers, no settings' ); SELECT set_eq( $$ SELECT empire_id , planet_id , resource_name , pres_income , pres_upkeep FROM bugs.dump_planet_resources_view WHERE resprov_quantity IS NOT NULL AND mining_priority IS NULL $$ , $$ VALUES ( _get_emp_name( 'empire1' ) , _get_map_name( 'planet1' ) , 'natRes1' , 3 , 4 ) $$ ); SELECT diag_test_name( 'bugs.dump_planet_resources_view - Records with resource providers and settings' ); SELECT set_eq( $$ SELECT empire_id , planet_id , resource_name , pres_income , pres_upkeep , mining_priority FROM bugs.dump_planet_resources_view WHERE resprov_quantity IS NOT NULL AND mining_priority IS NOT NULL $$ , $$ VALUES ( _get_emp_name( 'empire3' ) , _get_map_name( 'planet4' ) , 'natRes1' , 15 , 16 , 2 ) $$ ); SELECT * FROM finish( ); ROLLBACK;