| 1 |
/* |
| 2 |
* @progname st_convert.li |
| 3 |
* @version 1.01 (2002-12-14) |
| 4 |
* @author Perry Rapp |
| 5 |
* @category self-test |
| 6 |
* @output none |
| 7 |
* @description |
| 8 |
* |
| 9 |
* validate codeset conversion |
| 10 |
* |
| 11 |
*/ |
| 12 |
|
| 13 |
char_encoding("ASCII") |
| 14 |
|
| 15 |
require("lifelines-reports.version:1.3") |
| 16 |
option("explicitvars") /* Disallow use of undefined variables */ |
| 17 |
include("st_aux") |
| 18 |
|
| 19 |
/* entry point in case not invoked via st_all.ll */ |
| 20 |
proc main() |
| 21 |
{ |
| 22 |
call testConvert() |
| 23 |
} |
| 24 |
|
| 25 |
proc testConvert() |
| 26 |
{ |
| 27 |
call initSubsection() |
| 28 |
call convert_tests() |
| 29 |
call reportSubsection("convert tests") |
| 30 |
} |
| 31 |
|
| 32 |
proc convert_tests() |
| 33 |
{ |
| 34 |
/* we have to use bytecodes, b/c any non-ascii will be |
| 35 |
first converted by the report parser to internal codeset, |
| 36 |
which depends on the current database :( */ |
| 37 |
|
| 38 |
/* trivial test */ |
| 39 |
call checkconv("silver fox", "UTF-8", "silver fox", "ISO-8859-1") |
| 40 |
call checkconv("silver fox", "UTF-8", "silver fox", "ISO-8859-2") |
| 41 |
|
| 42 |
/* LATIN SMALL LETTER N WITH TILDE u000F1 */ |
| 43 |
call checkconv("$C3$B1", "UTF-8", "$F1", "ISO-8859-1") |
| 44 |
|
| 45 |
/* LATIN SMALL LETTER A WITH ACUTE u000E1 */ |
| 46 |
call checkconv("$C3$A1", "UTF-8", "$E1", "ISO-8859-1") |
| 47 |
call checkconv("$C3$A1", "UTF-8", "$E1", "ISO-8859-2") |
| 48 |
call checkconv("$C3$A1", "UTF-8", "$E1", "ISO-8859-3") |
| 49 |
call checkconv("$C3$A1", "UTF-8", "$E1", "ISO-8859-4") |
| 50 |
call checkconv("$C3$A1", "UTF-8", "$E1", "ISO-8859-15") |
| 51 |
|
| 52 |
/* LATIN CAPITAL LETTER L WITH STROKE u00141 */ |
| 53 |
call checkconv("$C5$81", "UTF-8", "$A3", "ISO-8859-2") |
| 54 |
call checkconv("$C5$81", "UTF-8", "$A1", "ANSEL") |
| 55 |
|
| 56 |
/* LATIN SMALL LETTER S WITH CEDILLA u0015F */ |
| 57 |
call checkconv("$C5$9F", "UTF-8", "$BA", "ISO-8859-2") |
| 58 |
call checkconv("$C5$9F", "UTF-8", "$BA", "ISO-8859-3") |
| 59 |
|
| 60 |
/* LATIN SMALL LETTER G WITH CEDILLA u00123 */ |
| 61 |
call checkconv("$C4$A3", "UTF-8", "$BB", "ISO-8859-4") |
| 62 |
|
| 63 |
/* LATIN SMALL LETTER AE u000E6 */ |
| 64 |
call checkconv("$C3$A6", "UTF-8", "$E6", "ISO-8859-1") |
| 65 |
call checkconv("$C3$A6", "UTF-8", "$B5", "ANSEL") |
| 66 |
|
| 67 |
/* LATIN CAPITAL LETTER N WITH CARON */ |
| 68 |
call checkconv("$C5$87", "UTF-8", "$D2", "ISO-8859-2") |
| 69 |
|
| 70 |
/* LATIN CAPITAL LETTER THORN u000DE */ |
| 71 |
call checkconv("$C3$9E", "UTF-8", "$DE", "ISO-8859-1") |
| 72 |
call checkconv("$C3$9E", "UTF-8", "$A4", "ANSEL") |
| 73 |
} |
| 74 |
|
| 75 |
/* test a conversion and its reverse */ |
| 76 |
proc checkconv(bc1, cs1, bc2, cs2) |
| 77 |
{ |
| 78 |
call checkconv_1way(bc1, cs1, bc2, cs2) |
| 79 |
call checkconv_1way(bc2, cs2, bc1, cs1) |
| 80 |
} |
| 81 |
|
| 82 |
/* test a single conversion */ |
| 83 |
proc checkconv_1way(bc1, cs1, bc2, cs2) |
| 84 |
{ |
| 85 |
set(str1, bytecode(bc1, "raw")) |
| 86 |
set(str2, bytecode(bc2, "raw")) |
| 87 |
if (ne(convertcode(str1, cs1, cs2), str2)) { |
| 88 |
set(fstr, concat("convertcode(bytecode(", bc1 |
| 89 |
, ",raw),", cs1, ",", cs2 |
| 90 |
, ") <> bytecode(", bc2, ",raw) FAILURE")) |
| 91 |
call reportfail(fstr) |
| 92 |
} else { incr(testok) } |
| 93 |
} |
| 94 |
|