Class UnicodeRoundTripTest


  • @SQLAction(provides="postgresql_unicodetest",implementor="postgresql_ge_90000",install="SELECT CASE WHEN \'UTF8\' = current_setting(\'server_encoding\') THEN set_config(\'pljava.implementors\', \'postgresql_unicodetest,\' || current_setting(\'pljava.implementors\'), true) END") @SQLAction(requires="unicodetest fn",implementor="postgresql_unicodetest",install="   with     usable_codepoints ( cp ) as (      select generate_series(1,x\'d7ff\'::int)      union all      select generate_series(x\'e000\'::int,x\'10ffff\'::int)     ),     test_inputs ( groupnum, cparray, s ) as (      select        cp / 1024 as groupnum,        array_agg(cp order by cp), string_agg(chr(cp), \'\' order by cp)      from usable_codepoints      group by groupnum     ),     test_outputs as (      select groupnum, cparray, s, unicodetest(s, cparray) as roundtrip      from test_inputs     ),     test_failures as (      select *      from test_outputs      where       cparray != (roundtrip).cparray or s != (roundtrip).s       or not (roundtrip).matched     ),     test_summary ( n_failing_groups, first_failing_group ) as (      select count(*), min(groupnum) from test_failures     )    select     case when n_failing_groups > 0 then      javatest.logmessage(\'WARNING\', n_failing_groups ||       \' 1k codepoint ranges had mismatches, first is block starting 0x\' ||       to_hex(1024 * first_failing_group))     else      javatest.logmessage(\'INFO\',         \'all Unicode codepoint ranges roundtripped successfully.\')     end     from test_summary") @SQLAction(install="CREATE TYPE unicodetestrow AS (matched boolean, cparray integer[], s text)",remove="DROP TYPE unicodetestrow",provides="unicodetestrow type")
    public class UnicodeRoundTripTest
    extends Object
    Test that strings containing characters from all Unicode planes are passed between PG and Java without alteration (issue 21).

    This function takes a string and an array of ints constructed in PG, such that PG believes the codepoints in the string to correspond exactly with the ints in the array. The function compares the two, generates a new array from the codepoints Java sees in the string and a new Java string from the original array, and returns a tuple (matched, cparray, s) where matched indicates whether the original array and string matched as seen by Java, and cparray and s are the new array and string generated in Java.

    The supplied test query generates all Unicode code points 1k at a time, calls this function on each (1k array, 1k string) pair, and counts a failure if matched is false or the original and returned arrays or strings do not match as seen in SQL.

    This example relies on implementor tags reflecting the PostgreSQL version, set up in the ConditionalDDR example, and also sets its own.

    • Method Detail

      • unicodetest

        @Function(type="unicodetestrow",
                  requires="unicodetestrow type",
                  provides="unicodetest fn")
        public static boolean unicodetest​(String s,
                                          int[] ints,
                                          ResultSet rs)
                                   throws SQLException
        This function takes a string and an array of ints constructed in PG, such that PG believes the codepoints in the string to correspond exactly with the ints in the array. The function compares the two, generates a new array from the codepoints Java sees in the string and a new Java string from the original array, and returns a tuple (matched, cparray, s) where matched indicates whether the original array and string matched as seen by Java, and cparray and s are the new array and string generated in Java.
        Parameters:
        s - A string, whose codepoints should match the entries of ints
        ints - Array of ints that should match the codepoints in s
        rs - OUT (matched, cparray, s) as described above
        Returns:
        true to indicate the OUT tuple is not null
        Throws:
        SQLException