BinaryStreamTest.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. <?php
  2. /**
  3. * Zend Framework
  4. *
  5. * LICENSE
  6. *
  7. * This source file is subject to the new BSD license that is bundled
  8. * with this package in the file LICENSE.txt.
  9. * It is also available through the world-wide-web at this URL:
  10. * http://framework.zend.com/license/new-bsd
  11. * If you did not receive a copy of the license and are unable to
  12. * obtain it through the world-wide-web, please send an email
  13. * to license@zend.com so we can send you a copy immediately.
  14. *
  15. * @category Zend
  16. * @package Zend_Amf
  17. * @subpackage UnitTests
  18. * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
  19. * @license http://framework.zend.com/license/new-bsd New BSD License
  20. * @version $Id$
  21. */
  22. if (!defined('PHPUnit_MAIN_METHOD')) {
  23. define('PHPUnit_MAIN_METHOD', 'Zend_Amf_Util_BinaryStreamTest::main');
  24. }
  25. require_once 'Zend/Amf/Util/BinaryStream.php';
  26. /**
  27. * Test case for Zend_Amf_Util_BinaryStream
  28. *
  29. * @category Zend
  30. * @package Zend_Amf
  31. * @subpackage UnitTests
  32. * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
  33. * @license http://framework.zend.com/license/new-bsd New BSD License
  34. * @group Zend_Amf
  35. */
  36. class Zend_Amf_Util_BinaryStreamTest extends PHPUnit_Framework_TestCase
  37. {
  38. /**
  39. * Runs the test methods of this class.
  40. *
  41. * @return void
  42. */
  43. public static function main()
  44. {
  45. $suite = new PHPUnit_Framework_TestSuite("Zend_Amf_Util_BinaryStreamTest");
  46. $result = PHPUnit_TextUI_TestRunner::run($suite);
  47. }
  48. /**
  49. * @expectedException Zend_Amf_Exception
  50. */
  51. public function testConstructorShouldThrowExceptionForInvalidStream()
  52. {
  53. $test = new Zend_Amf_Util_BinaryStream(array('foo', 'bar'));
  54. }
  55. /**
  56. * @expectedException Zend_Amf_Exception
  57. */
  58. public function testReadBytesShouldRaiseExceptionForBufferUnderrun()
  59. {
  60. $string = 'this is a short stream';
  61. $stream = new Zend_Amf_Util_BinaryStream($string);
  62. $length = strlen($string);
  63. $test = $stream->readBytes(10 * $length);
  64. }
  65. public function testReadBytesShouldReturnSubsetOfStringFromCurrentNeedle()
  66. {
  67. $string = 'this is a short stream';
  68. $stream = new Zend_Amf_Util_BinaryStream($string);
  69. $test = $stream->readBytes(4);
  70. $this->assertEquals('this', $test);
  71. $test = $stream->readBytes(5);
  72. $this->assertEquals(' is a', $test);
  73. }
  74. public function testBinaryStreamsShouldAllowWritingUtf8()
  75. {
  76. $string = str_repeat('赵勇', 1000);
  77. $stream = new Zend_Amf_Util_BinaryStream('');
  78. $stream->writeLongUtf($string);
  79. $test = $stream->getStream();
  80. $this->assertContains($string, $test);
  81. }
  82. }
  83. if (PHPUnit_MAIN_METHOD == 'Zend_Amf_Util_BinaryStreamTest::main') {
  84. Zend_Amf_Util_BinaryStreamTest::main();
  85. }