UsAsciiReaderTest.php 1.3KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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. {
  9. $c .= $bytes;
  10. $size = $v->validateCharacter($c);
  11. if (-1 == $size)
  12. {
  13. throw new Exception( ... invalid char .. );
  14. }
  15. elseif (0 == $size)
  16. {
  17. return $c; //next character in $os
  18. }
  19. }
  20. */
  21. private $_reader;
  22. public function setUp()
  23. {
  24. $this->_reader = new Swift_CharacterReader_UsAsciiReader();
  25. }
  26. public function testAllValidAsciiCharactersReturnZero()
  27. {
  28. for ($ordinal = 0x00; $ordinal <= 0x7F; ++$ordinal)
  29. {
  30. $this->assertIdentical(
  31. 0, $this->_reader->validateByteSequence(array($ordinal), 1)
  32. );
  33. }
  34. }
  35. public function testMultipleBytesAreInvalid()
  36. {
  37. for ($ordinal = 0x00; $ordinal <= 0x7F; $ordinal += 2)
  38. {
  39. $this->assertIdentical(
  40. -1, $this->_reader->validateByteSequence(array($ordinal, $ordinal + 1), 2)
  41. );
  42. }
  43. }
  44. public function testBytesAboveAsciiRangeAreInvalid()
  45. {
  46. for ($ordinal = 0x80; $ordinal <= 0xFF; ++$ordinal)
  47. {
  48. $this->assertIdentical(
  49. -1, $this->_reader->validateByteSequence(array($ordinal), 1)
  50. );
  51. }
  52. }
  53. }