Utf8ReaderTest.php 1.6KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. <?php
  2. require_once 'Swift/CharacterReader/Utf8Reader.php';
  3. class Swift_CharacterReader_Utf8ReaderTest
  4. extends UnitTestCase
  5. {
  6. private $_reader;
  7. public function setUp()
  8. {
  9. $this->_reader = new Swift_CharacterReader_Utf8Reader();
  10. }
  11. public function testLeading7BitOctetCausesReturnZero()
  12. {
  13. for ($ordinal = 0x00; $ordinal <= 0x7F; ++$ordinal)
  14. {
  15. $this->assertIdentical(
  16. 0, $this->_reader->validateByteSequence(array($ordinal), 1)
  17. );
  18. }
  19. }
  20. public function testLeadingByteOf2OctetCharCausesReturn1()
  21. {
  22. for ($octet = 0xC0; $octet <= 0xDF; ++$octet)
  23. {
  24. $this->assertIdentical(
  25. 1, $this->_reader->validateByteSequence(array($octet), 1)
  26. );
  27. }
  28. }
  29. public function testLeadingByteOf3OctetCharCausesReturn2()
  30. {
  31. for ($octet = 0xE0; $octet <= 0xEF; ++$octet)
  32. {
  33. $this->assertIdentical(
  34. 2, $this->_reader->validateByteSequence(array($octet), 1)
  35. );
  36. }
  37. }
  38. public function testLeadingByteOf4OctetCharCausesReturn3()
  39. {
  40. for ($octet = 0xF0; $octet <= 0xF7; ++$octet)
  41. {
  42. $this->assertIdentical(
  43. 3, $this->_reader->validateByteSequence(array($octet), 1)
  44. );
  45. }
  46. }
  47. public function testLeadingByteOf5OctetCharCausesReturn4()
  48. {
  49. for ($octet = 0xF8; $octet <= 0xFB; ++$octet)
  50. {
  51. $this->assertIdentical(
  52. 4, $this->_reader->validateByteSequence(array($octet),1)
  53. );
  54. }
  55. }
  56. public function testLeadingByteOf6OctetCharCausesReturn5()
  57. {
  58. for ($octet = 0xFC; $octet <= 0xFD; ++$octet)
  59. {
  60. $this->assertIdentical(
  61. 5, $this->_reader->validateByteSequence(array($octet),1)
  62. );
  63. }
  64. }
  65. }