1--TEST--
2Exhaustive test of verification and conversion of Big5 text
3--EXTENSIONS--
4mbstring
5--SKIPIF--
6<?php
7if (getenv("SKIP_SLOW_TESTS")) die("skip slow test");
8?>
9--FILE--
10<?php
11include('encoding_tests.inc');
12srand(1000); // Make results consistent
13mb_substitute_character(0x25); // '%'
14readConversionTable(__DIR__ . '/data/BIG5.txt', $toUnicode, $fromUnicode);
15
16// Non-reversible mappings (two different BIG5 codepoints map to same Unicode codepoint)
17$fromUnicode["\x25\x50"] = "\xA2\xA4";
18$fromUnicode["\x25\x5E"] = "\xA2\xA5";
19$fromUnicode["\x25\x61"] = "\xA2\xA7";
20$fromUnicode["\x25\x6A"] = "\xA2\xA6";
21$fromUnicode["\x25\x6D"] = "\xA2\x7E";
22$fromUnicode["\x25\x6E"] = "\xA2\xA1";
23$fromUnicode["\x25\x6F"] = "\xA2\xA3";
24$fromUnicode["\x25\x70"] = "\xA2\xA2";
25
26findInvalidChars($toUnicode, $invalid, $truncated);
27testAllValidChars($toUnicode, 'BIG5', 'UTF-16BE', false);
28testAllInvalidChars($invalid, $toUnicode, 'BIG5', 'UTF-16BE', "\x00%");
29testTruncatedChars($truncated, 'BIG5', 'UTF-16BE', "\x00%");
30echo "Tested BIG5 -> UTF-16BE\n";
31
32testAllValidChars($fromUnicode, 'UTF-16BE', 'BIG5', false);
33findInvalidChars($fromUnicode, $invalid, $unused, array_fill_keys(range(0,0xFF), 2));
34convertAllInvalidChars($invalid, $fromUnicode, 'UTF-16BE', 'BIG5', '%');
35echo "Tested UTF-16BE -> BIG5\n";
36
37// Test "long" illegal character markers
38mb_substitute_character("long");
39convertInvalidString("\x80", "%", "BIG5", "UTF-8");
40convertInvalidString("\xB0\x9F", "%", "BIG5", "UTF-8");
41convertInvalidString("\xA3\xED", "%", "BIG5", "UTF-8");
42convertInvalidString("\x76\x54", "U+7654", "UTF-16BE", "BIG5");
43
44echo "Done!\n";
45?>
46--EXPECT--
47Tested BIG5 -> UTF-16BE
48Tested UTF-16BE -> BIG5
49Done!
50