1--TEST-- 2Exhaustive test of verification and conversion of CP950 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/CP950.txt', $toUnicode, $fromUnicode); 15 16// Non-reversible mappings (two different CP950 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 26// CP950 explicitly maps some unused Big5 codepoint ranges to Unicode "Private User Area" codepoints 27 28function addPUAMapping($hi, $lo, $unicode) { 29 global $fromUnicode, $toUnicode; 30 $cp950 = pack('n', ($hi << 8) + $lo); 31 $unicode = pack('n', $unicode); 32 $fromUnicode[$unicode] = $cp950; 33 $toUnicode[$cp950] = $unicode; 34} 35 36for ($hi = 0x81; $hi <= 0x8D; $hi++) { 37 for ($lo = 0x40; $lo <= 0x7E; $lo++) 38 addPUAMapping($hi, $lo, 0xEEB8 + (157 * ($hi - 0x81)) + ($lo - 0x40)); 39 for ($lo = 0xA1; $lo <= 0xFE; $lo++) 40 addPUAMapping($hi, $lo, 0xEEB8 + (157 * ($hi - 0x81)) + ($lo - 0x62)); 41} 42 43for ($hi = 0x8E; $hi <= 0xA0; $hi++) { 44 for ($lo = 0x40; $lo <= 0x7E; $lo++) 45 addPUAMapping($hi, $lo, 0xE311 + (157 * ($hi - 0x8E)) + ($lo - 0x40)); 46 for ($lo = 0xA1; $lo <= 0xFE; $lo++) 47 addPUAMapping($hi, $lo, 0xE311 + (157 * ($hi - 0x8E)) + ($lo - 0x62)); 48} 49 50$hi = 0xC6; 51for ($lo = 0xA1; $lo <= 0xFE; $lo++) 52 addPUAMapping($hi, $lo, 0xF672 + (157 * ($hi - 0xC6)) + ($lo - 0x62)); 53 54for ($hi = 0xC7; $hi <= 0xC8; $hi++) { 55 for ($lo = 0x40; $lo <= 0x7E; $lo++) 56 addPUAMapping($hi, $lo, 0xF672 + (157 * ($hi - 0xC6)) + ($lo - 0x40)); 57 for ($lo = 0xA1; $lo <= 0xFE; $lo++) 58 addPUAMapping($hi, $lo, 0xF672 + (157 * ($hi - 0xC6)) + ($lo - 0x62)); 59} 60 61for ($hi = 0xFA; $hi <= 0xFE; $hi++) { 62 for ($lo = 0x40; $lo <= 0x7E; $lo++) 63 addPUAMapping($hi, $lo, 0xE000 + (157 * ($hi - 0xFA)) + ($lo - 0x40)); 64 for ($lo = 0xA1; $lo <= 0xFE; $lo++) 65 addPUAMapping($hi, $lo, 0xE000 + (157 * ($hi - 0xFA)) + ($lo - 0x62)); 66} 67 68findInvalidChars($toUnicode, $invalid, $truncated); 69testAllValidChars($toUnicode, 'CP950', 'UTF-16BE', false); 70testAllInvalidChars($invalid, $toUnicode, 'CP950', 'UTF-16BE', "\x00%"); 71testTruncatedChars($truncated, 'CP950', 'UTF-16BE', "\x00%"); 72echo "Tested CP950 -> UTF-16BE\n"; 73 74testAllValidChars($fromUnicode, 'UTF-16BE', 'CP950', false); 75findInvalidChars($fromUnicode, $invalid, $unused, array_fill_keys(range(0,0xFF), 2)); 76convertAllInvalidChars($invalid, $fromUnicode, 'UTF-16BE', 'CP950', '%'); 77echo "Tested UTF-16BE -> CP950\n"; 78 79// Test "long" illegal character markers 80mb_substitute_character("long"); 81convertInvalidString("\x80", "%", "CP950", "UTF-8"); 82convertInvalidString("\x26\x09", "U+2609", "UTF-16BE", "CP950"); 83 84echo "Done!\n"; 85?> 86--EXPECT-- 87Tested CP950 -> UTF-16BE 88Tested UTF-16BE -> CP950 89Done! 90