1--TEST--
2Exhaustive test of verification and conversion of ARMSCII-8 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(111); // Make results consistent
13mb_substitute_character(0x25); // '%'
14
15readConversionTable(__DIR__ . '/data/ARMSCII-8.txt', $toUnicode, $fromUnicode);
16$irreversible = ["\x28", "\x29", "\x2C", "\x2D", "\x2E"];
17
18findInvalidChars($toUnicode, $invalid, $truncated);
19testAllValidChars($toUnicode, 'ARMSCII-8', 'UTF-16BE', false);
20foreach ($irreversible as $char)
21  unset($toUnicode[$char]);
22testAllValidChars($toUnicode, 'ARMSCII-8', 'UTF-16BE');
23testAllInvalidChars($invalid, $toUnicode, 'ARMSCII-8', 'UTF-16BE', "\x00%");
24testTruncatedChars($truncated, 'ARMSCII-8', 'UTF-16BE', "\x00%");
25echo "Tested ARMSCII-8 -> UTF-16BE\n";
26
27findInvalidChars($fromUnicode, $invalid, $unused, array_fill_keys(range(0,0xFF), 2));
28convertAllInvalidChars($invalid, $fromUnicode, 'UTF-16BE', 'ARMSCII-8', '%');
29echo "Tested UTF-16BE -> ARMSCII-8\n";
30
31// Test "long" illegal character markers
32mb_substitute_character("long");
33convertInvalidString("\xA1", "%", "ARMSCII-8", "UTF-8");
34convertInvalidString("\xFF", "%", "ARMSCII-8", "UTF-8");
35
36// Test replacement character which cannot be encoded in ARMSCII-8
37mb_substitute_character(0x1234);
38convertInvalidString("\x23\x45", '?', 'UTF-16BE', 'ARMSCII-8');
39
40echo "Done!\n";
41?>
42--EXPECT--
43Tested ARMSCII-8 -> UTF-16BE
44Tested UTF-16BE -> ARMSCII-8
45Done!
46