Utf8ReaderTest.php 1.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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. $this->assertIdentical(
  15. 0, $this->_reader->validateByteSequence(array($ordinal), 1)
  16. );
  17. }
  18. }
  19. public function testLeadingByteOf2OctetCharCausesReturn1()
  20. {
  21. for ($octet = 0xC0; $octet <= 0xDF; ++$octet) {
  22. $this->assertIdentical(
  23. 1, $this->_reader->validateByteSequence(array($octet), 1)
  24. );
  25. }
  26. }
  27. public function testLeadingByteOf3OctetCharCausesReturn2()
  28. {
  29. for ($octet = 0xE0; $octet <= 0xEF; ++$octet) {
  30. $this->assertIdentical(
  31. 2, $this->_reader->validateByteSequence(array($octet), 1)
  32. );
  33. }
  34. }
  35. public function testLeadingByteOf4OctetCharCausesReturn3()
  36. {
  37. for ($octet = 0xF0; $octet <= 0xF7; ++$octet) {
  38. $this->assertIdentical(
  39. 3, $this->_reader->validateByteSequence(array($octet), 1)
  40. );
  41. }
  42. }
  43. public function testLeadingByteOf5OctetCharCausesReturn4()
  44. {
  45. for ($octet = 0xF8; $octet <= 0xFB; ++$octet) {
  46. $this->assertIdentical(
  47. 4, $this->_reader->validateByteSequence(array($octet),1)
  48. );
  49. }
  50. }
  51. public function testLeadingByteOf6OctetCharCausesReturn5()
  52. {
  53. for ($octet = 0xFC; $octet <= 0xFD; ++$octet) {
  54. $this->assertIdentical(
  55. 5, $this->_reader->validateByteSequence(array($octet),1)
  56. );
  57. }
  58. }
  59. }