/* * Test the defs.uoc_natural_resource() functions */ BEGIN; /* Create a fake internal function that will just push its parameters to * a temporary table. */ CREATE TEMPORARY TABLE calls_to_internal( name TEXT , description TEXT , category TEXT , weight INT , presence DOUBLE PRECISION , quantity_avg DOUBLE PRECISION , quantity_dev DOUBLE PRECISION , difficulty_avg DOUBLE PRECISION , difficulty_dev DOUBLE PRECISION , recovery_avg DOUBLE PRECISION , recovery_dev DOUBLE PRECISION ) ON COMMIT DROP; CREATE OR REPLACE FUNCTION defs.uoc_natres_internal( _name TEXT , _description TEXT , _category TEXT , _weight INT , _presence DOUBLE PRECISION , _quantity_avg DOUBLE PRECISION , _quantity_dev DOUBLE PRECISION , _difficulty_avg DOUBLE PRECISION , _difficulty_dev DOUBLE PRECISION , _recovery_avg DOUBLE PRECISION , _recovery_dev DOUBLE PRECISION ) RETURNS defs.resource_update_result CALLED ON NULL INPUT VOLATILE SECURITY INVOKER AS $$ INSERT INTO calls_to_internal VALUES ( $1 , $2 , CASE WHEN $3 IS NULL THEN 'NULL' ELSE $3 END , $4 , $5 , $6 , $7 , $8 , $9 , $10 , $11 ); SELECT 'BAD_STRINGS'::defs.resource_update_result; $$ LANGUAGE SQL; /****** TESTS BEGIN HERE ******/ SELECT plan( 2 ); SELECT diag_test_name( 'defs.uoc_natural_resource() - Calls internal function (without category)' ); SELECT defs.uoc_natural_resource( 'a' , 'b' , 1 , 0.1 , 0.2 , 0.3 , 0.4 , 0.5 , 0.6 , 0.7 ); SELECT set_eq( $$ SELECT * FROM calls_to_internal; $$ , $$ VALUES( 'a' , 'b' , 'NULL' , 1 , 0.1 , 0.2 , 0.3 , 0.4 , 0.5 , 0.6 , 0.7 ) $$ ); DELETE FROM calls_to_internal; SELECT diag_test_name( 'defs.uoc_natural_resource() - Calls internal function (with category)' ); SELECT defs.uoc_natural_resource( 'a' , 'b' , 'c' , 1 , 0.1 , 0.2 , 0.3 , 0.4 , 0.5 , 0.6 , 0.7 ); SELECT set_eq( $$ SELECT * FROM calls_to_internal; $$ , $$ VALUES( 'a' , 'b' , 'c' , 1 , 0.1 , 0.2 , 0.3 , 0.4 , 0.5 , 0.6 , 0.7 ) $$ ); DELETE FROM calls_to_internal; SELECT * FROM finish( ); ROLLBACK;