/*
 * Utility functions used by unit tests
 *
 * I18N string creation and access
 */


/*
 * Function that returns an invalid string identifier.
 */
CREATE FUNCTION _get_bad_string( ) RETURNS INT AS $$
	SELECT MAX( id ) + 1 FROM defs.strings;
$$ LANGUAGE SQL;


/*
 * Function that returns a language's identifier
 */
CREATE FUNCTION _get_language( TEXT ) RETURNS INT AS $$
	SELECT id FROM defs.languages WHERE language = $1;
$$ LANGUAGE SQL;


/*
 * Function that returns a string's identifier
 */
CREATE FUNCTION _get_string( TEXT ) RETURNS INT AS $$
	SELECT id FROM defs.strings WHERE name = $1;
$$ LANGUAGE SQL;


/*
 * Function that creates some quantity of test strings
 */
CREATE FUNCTION _create_test_strings( _quantity INT )
		RETURNS VOID
	AS $$
DECLARE
	i	INT;
BEGIN
	PERFORM _create_test_strings( _quantity , 'test' );
END;
$$ LANGUAGE PLPGSQL;


/*
 * Function that creates some quantity of test strings using a specific prefix
 */
CREATE FUNCTION _create_test_strings( _quantity INT , _prefix TEXT )
		RETURNS VOID
	AS $$
DECLARE
	i	INT;
BEGIN
	PERFORM defs.uoc_language( 't' , 'Test' );

	i := 0;
	WHILE i < _quantity
	LOOP
		i := i + 1;
		PERFORM defs.uoc_translation( 't' , _prefix || i::TEXT ,
			'Test string #' || i::TEXT );
	END LOOP;
END;
$$ LANGUAGE PLPGSQL;