GenericFixedWidthReaderTest.php 1.3KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. <?php
  2. require_once 'Swift/CharacterReader/GenericFixedWidthReader.php';
  3. class Swift_CharacterReader_GenericFixedWidthReaderTest
  4. extends UnitTestCase
  5. {
  6. public function testInitialByteSizeMatchesWidth()
  7. {
  8. $reader = new Swift_CharacterReader_GenericFixedWidthReader(1);
  9. $this->assertIdentical(1, $reader->getInitialByteSize());
  10. $reader = new Swift_CharacterReader_GenericFixedWidthReader(4);
  11. $this->assertIdentical(4, $reader->getInitialByteSize());
  12. }
  13. public function testValidationValueIsBasedOnOctetCount()
  14. {
  15. $reader = new Swift_CharacterReader_GenericFixedWidthReader(4);
  16. $this->assertIdentical(
  17. 1, $reader->validateByteSequence(array(0x01, 0x02, 0x03), 3)
  18. ); //3 octets
  19. $this->assertIdentical(
  20. 2, $reader->validateByteSequence(array(0x01, 0x0A), 2)
  21. ); //2 octets
  22. $this->assertIdentical(
  23. 3, $reader->validateByteSequence(array(0xFE), 1)
  24. ); //1 octet
  25. $this->assertIdentical(
  26. 0, $reader->validateByteSequence(array(0xFE, 0x03, 0x67, 0x9A), 4)
  27. ); //All 4 octets
  28. }
  29. public function testValidationFailsIfTooManyOctets()
  30. {
  31. $reader = new Swift_CharacterReader_GenericFixedWidthReader(6);
  32. $this->assertIdentical(-1, $reader->validateByteSequence(
  33. array(0xFE, 0x03, 0x67, 0x9A, 0x10, 0x09, 0x85), 7
  34. )); //7 octets
  35. }
  36. }