BinaryStreamTest.php 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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-2010 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 dirname(__FILE__) . '/../../../TestHelper.php';
  26. require_once 'Zend/Amf/Util/BinaryStream.php';
  27. /**
  28. * Test case for Zend_Amf_Util_BinaryStream
  29. *
  30. * @category Zend
  31. * @package Zend_Amf
  32. * @subpackage UnitTests
  33. * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
  34. * @license http://framework.zend.com/license/new-bsd New BSD License
  35. * @group Zend_Amf
  36. */
  37. class Zend_Amf_Util_BinaryStreamTest extends PHPUnit_Framework_TestCase
  38. {
  39. /**
  40. * Runs the test methods of this class.
  41. *
  42. * @return void
  43. */
  44. public static function main()
  45. {
  46. $suite = new PHPUnit_Framework_TestSuite("Zend_Amf_Util_BinaryStreamTest");
  47. $result = PHPUnit_TextUI_TestRunner::run($suite);
  48. }
  49. /**
  50. * @expectedException Zend_Amf_Exception
  51. */
  52. public function testConstructorShouldThrowExceptionForInvalidStream()
  53. {
  54. $test = new Zend_Amf_Util_BinaryStream(array('foo', 'bar'));
  55. }
  56. /**
  57. * @expectedException Zend_Amf_Exception
  58. */
  59. public function testReadBytesShouldRaiseExceptionForBufferUnderrun()
  60. {
  61. $string = 'this is a short stream';
  62. $stream = new Zend_Amf_Util_BinaryStream($string);
  63. $length = strlen($string);
  64. $test = $stream->readBytes(10 * $length);
  65. }
  66. public function testReadBytesShouldReturnSubsetOfStringFromCurrentNeedle()
  67. {
  68. $string = 'this is a short stream';
  69. $stream = new Zend_Amf_Util_BinaryStream($string);
  70. $test = $stream->readBytes(4);
  71. $this->assertEquals('this', $test);
  72. $test = $stream->readBytes(5);
  73. $this->assertEquals(' is a', $test);
  74. }
  75. public function testBinaryStreamsShouldAllowWritingUtf8()
  76. {
  77. $string = str_repeat('赵勇', 1000);
  78. $stream = new Zend_Amf_Util_BinaryStream('');
  79. $stream->writeLongUtf($string);
  80. $test = $stream->getStream();
  81. $this->assertContains($string, $test);
  82. }
  83. }
  84. if (PHPUnit_MAIN_METHOD == 'Zend_Amf_Util_BinaryStreamTest::main') {
  85. Zend_Amf_Util_BinaryStreamTest::main();
  86. }