2011-12-19 11:57:08 +01:00
|
|
|
/*
|
2012-01-10 10:17:47 +01:00
|
|
|
* Test constraints and foreign keys on emp.planet_mining_settings
|
2011-12-19 11:57:08 +01:00
|
|
|
*/
|
|
|
|
BEGIN;
|
|
|
|
|
|
|
|
/* We need to create a pair of resources, a pair of empires, a pair of planets, and resource providers */
|
|
|
|
\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 , 'testResource' );
|
|
|
|
SELECT _create_emp_names( 2 , 'testUser' );
|
|
|
|
INSERT INTO emp.empires ( name_id , cash )
|
|
|
|
SELECT id , 0 FROM naming.empire_names;
|
|
|
|
SELECT _create_raw_planets( 2 , 'testPlanet' );
|
|
|
|
SELECT _create_resource_provider( 'testPlanet1' , 'testResource1' );
|
|
|
|
SELECT _create_resource_provider( 'testPlanet1' , 'testResource2' );
|
|
|
|
SELECT _create_resource_provider( 'testPlanet2' , 'testResource1' );
|
|
|
|
-- No provider for testResource2 on testPlanet2
|
|
|
|
|
|
|
|
/****** TESTS BEGIN HERE ******/
|
2012-01-10 10:17:47 +01:00
|
|
|
SELECT plan( 17 );
|
2011-12-19 11:57:08 +01:00
|
|
|
|
|
|
|
|
2012-01-10 10:17:47 +01:00
|
|
|
SELECT diag_test_name( 'emp.planet_mining_settings - Valid record' );
|
2011-12-19 11:57:08 +01:00
|
|
|
PREPARE _test_this AS
|
|
|
|
INSERT INTO emp.planet_mining_settings(
|
|
|
|
empire_id , planet_id ,
|
|
|
|
resource_name_id , emppmset_weight
|
|
|
|
) VALUES (
|
|
|
|
_get_emp_name( 'testUser1' ) , _get_map_name( 'testPlanet1' ) ,
|
|
|
|
_get_string( 'testResource1' ) , 0
|
|
|
|
);
|
|
|
|
SELECT lives_ok( '_test_this' );
|
|
|
|
|
2012-01-10 10:17:47 +01:00
|
|
|
SELECT diag_test_name( 'emp.planet_mining_settings - Duplicate record' );
|
2011-12-19 11:57:08 +01:00
|
|
|
SELECT throws_ok( '_test_this' , 23505 );
|
|
|
|
DEALLOCATE ALL;
|
|
|
|
|
2012-01-10 10:17:47 +01:00
|
|
|
SELECT diag_test_name( 'emp.planet_mining_settings - Different types' );
|
2011-12-19 11:57:08 +01:00
|
|
|
PREPARE _test_this AS
|
|
|
|
INSERT INTO emp.planet_mining_settings(
|
|
|
|
empire_id , planet_id ,
|
|
|
|
resource_name_id , emppmset_weight
|
|
|
|
) VALUES (
|
|
|
|
_get_emp_name( 'testUser1' ) , _get_map_name( 'testPlanet1' ) ,
|
|
|
|
_get_string( 'testResource2' ) , 0
|
|
|
|
);
|
|
|
|
SELECT lives_ok( '_test_this' );
|
|
|
|
DEALLOCATE ALL;
|
|
|
|
|
2012-01-10 10:17:47 +01:00
|
|
|
SELECT diag_test_name( 'emp.planet_mining_settings - Different empires' );
|
2011-12-19 11:57:08 +01:00
|
|
|
PREPARE _test_this AS
|
|
|
|
INSERT INTO emp.planet_mining_settings(
|
|
|
|
empire_id , planet_id ,
|
|
|
|
resource_name_id , emppmset_weight
|
|
|
|
) VALUES (
|
|
|
|
_get_emp_name( 'testUser2' ) , _get_map_name( 'testPlanet1' ) ,
|
|
|
|
_get_string( 'testResource1' ) , 0
|
|
|
|
);
|
|
|
|
SELECT lives_ok( '_test_this' );
|
|
|
|
DEALLOCATE ALL;
|
|
|
|
|
2012-01-10 10:17:47 +01:00
|
|
|
SELECT diag_test_name( 'emp.planet_mining_settings - Different planets' );
|
2011-12-19 11:57:08 +01:00
|
|
|
PREPARE _test_this AS
|
|
|
|
INSERT INTO emp.planet_mining_settings(
|
|
|
|
empire_id , planet_id ,
|
|
|
|
resource_name_id , emppmset_weight
|
|
|
|
) VALUES (
|
|
|
|
_get_emp_name( 'testUser1' ) , _get_map_name( 'testPlanet2' ) ,
|
|
|
|
_get_string( 'testResource1' ) , 0
|
|
|
|
);
|
|
|
|
SELECT lives_ok( '_test_this' );
|
|
|
|
DEALLOCATE ALL;
|
2012-01-10 10:17:47 +01:00
|
|
|
DELETE FROM emp.planet_mining_settings;
|
2011-12-19 11:57:08 +01:00
|
|
|
|
2012-01-10 10:17:47 +01:00
|
|
|
SELECT diag_test_name( 'emp.planet_mining_settings - Valid record with default weight' );
|
|
|
|
PREPARE _test_this AS
|
|
|
|
INSERT INTO emp.planet_mining_settings(
|
|
|
|
empire_id , planet_id , resource_name_id
|
|
|
|
) VALUES (
|
|
|
|
_get_emp_name( 'testUser1' ) , _get_map_name( 'testPlanet1' ) ,
|
|
|
|
_get_string( 'testResource1' )
|
|
|
|
);
|
|
|
|
SELECT lives_ok( '_test_this' );
|
|
|
|
DEALLOCATE ALL;
|
|
|
|
|
|
|
|
SELECT diag_test_name( 'emp.planet_mining_settings - Default weight = 2' );
|
|
|
|
SELECT is( emppmset_weight , 2 ) FROM emp.planet_mining_settings;
|
|
|
|
DELETE FROM emp.planet_mining_settings;
|
2011-12-19 11:57:08 +01:00
|
|
|
|
2012-01-10 10:17:47 +01:00
|
|
|
|
|
|
|
SELECT diag_test_name( 'emp.planet_mining_settings - NULL empire identifier' );
|
2011-12-19 11:57:08 +01:00
|
|
|
PREPARE _test_this AS
|
|
|
|
INSERT INTO emp.planet_mining_settings(
|
|
|
|
empire_id , planet_id ,
|
|
|
|
resource_name_id , emppmset_weight
|
|
|
|
) VALUES (
|
|
|
|
NULL , _get_map_name( 'testPlanet2' ) ,
|
|
|
|
_get_string( 'testResource1' ) , 0
|
|
|
|
);
|
|
|
|
SELECT throws_ok( '_test_this' , 23502 );
|
|
|
|
DEALLOCATE ALL;
|
|
|
|
|
2012-01-10 10:17:47 +01:00
|
|
|
SELECT diag_test_name( 'emp.planet_mining_settings - Invalid empire identifier' );
|
2011-12-19 11:57:08 +01:00
|
|
|
PREPARE _test_this AS
|
|
|
|
INSERT INTO emp.planet_mining_settings(
|
|
|
|
empire_id , planet_id ,
|
|
|
|
resource_name_id , emppmset_weight
|
|
|
|
) VALUES (
|
|
|
|
_get_bad_emp_name( ) , _get_map_name( 'testPlanet2' ) ,
|
|
|
|
_get_string( 'testResource1' ) , 0
|
|
|
|
);
|
|
|
|
SELECT throws_ok( '_test_this' , 23503 );
|
|
|
|
DEALLOCATE ALL;
|
|
|
|
|
|
|
|
|
2012-01-10 10:17:47 +01:00
|
|
|
SELECT diag_test_name( 'emp.planet_mining_settings - NULL planet identifier' );
|
2011-12-19 11:57:08 +01:00
|
|
|
PREPARE _test_this AS
|
|
|
|
INSERT INTO emp.planet_mining_settings(
|
|
|
|
empire_id , planet_id ,
|
|
|
|
resource_name_id , emppmset_weight
|
|
|
|
) VALUES (
|
|
|
|
_get_emp_name( 'testUser1' ) , NULL ,
|
|
|
|
_get_string( 'testResource1' ) , 0
|
|
|
|
);
|
|
|
|
SELECT throws_ok( '_test_this' , 23502 );
|
|
|
|
DEALLOCATE ALL;
|
|
|
|
|
2012-01-10 10:17:47 +01:00
|
|
|
SELECT diag_test_name( 'emp.planet_mining_settings - Invalid planet identifier' );
|
2011-12-19 11:57:08 +01:00
|
|
|
PREPARE _test_this AS
|
|
|
|
INSERT INTO emp.planet_mining_settings(
|
|
|
|
empire_id , planet_id ,
|
|
|
|
resource_name_id , emppmset_weight
|
|
|
|
) VALUES (
|
|
|
|
_get_emp_name( 'testUser1' ) , _get_bad_map_name( ) ,
|
|
|
|
_get_string( 'testResource1' ) , 0
|
|
|
|
);
|
|
|
|
SELECT throws_ok( '_test_this' , 23503 );
|
|
|
|
DEALLOCATE ALL;
|
|
|
|
|
|
|
|
|
2012-01-10 10:17:47 +01:00
|
|
|
SELECT diag_test_name( 'emp.planet_mining_settings - NULL resource identifier' );
|
2011-12-19 11:57:08 +01:00
|
|
|
PREPARE _test_this AS
|
|
|
|
INSERT INTO emp.planet_mining_settings(
|
|
|
|
empire_id , planet_id ,
|
|
|
|
resource_name_id , emppmset_weight
|
|
|
|
) VALUES (
|
|
|
|
_get_emp_name( 'testUser1' ) , _get_map_name( 'testPlanet2' ) ,
|
|
|
|
NULL , 0
|
|
|
|
);
|
|
|
|
SELECT throws_ok( '_test_this' , 23502 );
|
|
|
|
DEALLOCATE ALL;
|
|
|
|
|
2012-01-10 10:17:47 +01:00
|
|
|
SELECT diag_test_name( 'emp.planet_mining_settings - Invalid resource identifier' );
|
2011-12-19 11:57:08 +01:00
|
|
|
PREPARE _test_this AS
|
|
|
|
INSERT INTO emp.planet_mining_settings(
|
|
|
|
empire_id , planet_id ,
|
|
|
|
resource_name_id , emppmset_weight
|
|
|
|
) VALUES (
|
|
|
|
_get_emp_name( 'testUser1' ) , _get_map_name( 'testPlanet2' ) ,
|
|
|
|
_get_bad_string( ) , 0
|
|
|
|
);
|
|
|
|
SELECT throws_ok( '_test_this' , 23503 );
|
|
|
|
DEALLOCATE ALL;
|
|
|
|
|
|
|
|
|
2012-01-10 10:17:47 +01:00
|
|
|
SELECT diag_test_name( 'emp.planet_mining_settings - Invalid resource provider identifier' );
|
2011-12-19 11:57:08 +01:00
|
|
|
PREPARE _test_this AS
|
|
|
|
INSERT INTO emp.planet_mining_settings(
|
|
|
|
empire_id , planet_id ,
|
|
|
|
resource_name_id , emppmset_weight
|
|
|
|
) VALUES (
|
|
|
|
_get_emp_name( 'testUser1' ) , _get_map_name( 'testPlanet2' ) ,
|
|
|
|
_get_string( 'testResource2' ) , 0
|
|
|
|
);
|
|
|
|
SELECT throws_ok( '_test_this' , 23503 );
|
|
|
|
DEALLOCATE ALL;
|
|
|
|
|
|
|
|
|
2012-01-10 10:17:47 +01:00
|
|
|
SELECT diag_test_name( 'emp.planet_mining_settings - NULL weight' );
|
2011-12-19 11:57:08 +01:00
|
|
|
PREPARE _test_this AS
|
|
|
|
INSERT INTO emp.planet_mining_settings(
|
|
|
|
empire_id , planet_id ,
|
|
|
|
resource_name_id , emppmset_weight
|
|
|
|
) VALUES (
|
|
|
|
_get_emp_name( 'testUser1' ) , _get_map_name( 'testPlanet1' ) ,
|
|
|
|
_get_string( 'testResource1' ) , NULL
|
|
|
|
);
|
|
|
|
SELECT throws_ok( '_test_this' , 23502 );
|
|
|
|
DEALLOCATE ALL;
|
|
|
|
|
2012-01-10 10:17:47 +01:00
|
|
|
SELECT diag_test_name( 'emp.planet_mining_settings - Weight < 0' );
|
2011-12-19 11:57:08 +01:00
|
|
|
PREPARE _test_this AS
|
|
|
|
INSERT INTO emp.planet_mining_settings(
|
|
|
|
empire_id , planet_id ,
|
|
|
|
resource_name_id , emppmset_weight
|
|
|
|
) VALUES (
|
|
|
|
_get_emp_name( 'testUser1' ) , _get_map_name( 'testPlanet1' ) ,
|
|
|
|
_get_string( 'testResource1' ) , -1
|
|
|
|
);
|
|
|
|
SELECT throws_ok( '_test_this' , 23514 );
|
|
|
|
DEALLOCATE ALL;
|
|
|
|
|
2012-01-10 10:17:47 +01:00
|
|
|
SELECT diag_test_name( 'emp.planet_mining_settings - Weight > 4' );
|
|
|
|
PREPARE _test_this AS
|
|
|
|
INSERT INTO emp.planet_mining_settings(
|
|
|
|
empire_id , planet_id ,
|
|
|
|
resource_name_id , emppmset_weight
|
|
|
|
) VALUES (
|
|
|
|
_get_emp_name( 'testUser1' ) , _get_map_name( 'testPlanet1' ) ,
|
|
|
|
_get_string( 'testResource1' ) , 5
|
|
|
|
);
|
|
|
|
SELECT throws_ok( '_test_this' , 23514 );
|
|
|
|
DEALLOCATE ALL;
|
|
|
|
|
2011-12-19 11:57:08 +01:00
|
|
|
|
|
|
|
SELECT * FROM finish( );
|
|
|
|
ROLLBACK;
|