This repository has been archived on 2025-01-04. You can view files and clone it, but cannot push or open issues or pull requests.
lwb6/legacyworlds-server-data/db-structure/tests/admin/constraints/defs/11002-empire-mining-settings.sql
Emmanuel BENOîT 4e1bb91780 Resource database structures
* Added structures for resource definitions, natural resources
definitions, resource providers, empire resources and empire mining
settings (both empire-wide and planet-specific).

* Added a few common utility functions to the SQL test suite. These
functions allow test initialisation to be a little shorter.

* Added "MINE" production type and an associated building definition.
The production will not be added to the XML dump or to the output of the
planets summary page, as this is extremely temporary.
2011-12-19 11:57:08 +01:00

119 lines
No EOL
3.6 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( 10 );
SELECT diag_test_name( 'Valid empire mining settings 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( 'Duplicate empire mining settings record' );
SELECT throws_ok( '_test_this' , 23505 );
DEALLOCATE ALL;
SELECT diag_test_name( 'Empire mining settings records with same empire but 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( 'Empire mining settings records with same type but 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( 'Empire mining settings record with 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( 'Empire mining settings record with 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( 'Empire mining settings record with 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( 'Empire mining settings record with 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( 'Empire mining settings record with 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( 'Empire mining settings record with 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 * FROM finish( );
ROLLBACK;