UsAsciiReaderTest.php 1.4KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. <?php
  2. require_once 'Swift/CharacterReader/UsAsciiReader.php';
  3. class Swift_CharacterReader_UsAsciiReaderTest
  4. extends UnitTestCase
  5. {
  6. /*
  7. for ($c = '', $size = 1; false !== $bytes = $os->read($size); ) {
  8. $c .= $bytes;
  9. $size = $v->validateCharacter($c);
  10. if (-1 == $size) {
  11. throw new Exception( ... invalid char .. );
  12. } elseif (0 == $size) {
  13. return $c; //next character in $os
  14. }
  15. }
  16. */
  17. private $_reader;
  18. public function setUp()
  19. {
  20. $this->_reader = new Swift_CharacterReader_UsAsciiReader();
  21. }
  22. public function testAllValidAsciiCharactersReturnZero()
  23. {
  24. for ($ordinal = 0x00; $ordinal <= 0x7F; ++$ordinal) {
  25. $this->assertIdentical(
  26. 0, $this->_reader->validateByteSequence(array($ordinal), 1)
  27. );
  28. }
  29. }
  30. public function testMultipleBytesAreInvalid()
  31. {
  32. for ($ordinal = 0x00; $ordinal <= 0x7F; $ordinal += 2) {
  33. $this->assertIdentical(
  34. -1, $this->_reader->validateByteSequence(array($ordinal, $ordinal + 1), 2)
  35. );
  36. }
  37. }
  38. public function testBytesAboveAsciiRangeAreInvalid()
  39. {
  40. for ($ordinal = 0x80; $ordinal <= 0xFF; ++$ordinal) {
  41. $this->assertIdentical(
  42. -1, $this->_reader->validateByteSequence(array($ordinal), 1)
  43. );
  44. }
  45. }
  46. }