PythonPickleSerializeProtocol1Test.php 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  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_Serializer
  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. /**
  23. * @see Zend_Serializer_Adapter_PythonPickle
  24. */
  25. require_once 'Zend/Serializer/Adapter/PythonPickle.php';
  26. /**
  27. * PHPUnit test case
  28. */
  29. require_once 'PHPUnit/Framework/TestCase.php';
  30. /**
  31. * @category Zend
  32. * @package Zend_Serializer
  33. * @subpackage UnitTests
  34. * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
  35. * @license http://framework.zend.com/license/new-bsd New BSD License
  36. */
  37. class Zend_Serializer_Adapter_PythonPickleSerializeProtocol1Test extends PHPUnit_Framework_TestCase
  38. {
  39. private $_adapter;
  40. public function setUp()
  41. {
  42. $this->_adapter = new Zend_Serializer_Adapter_PythonPickle(array('protocol' => 1));
  43. }
  44. public function tearDown()
  45. {
  46. $this->_adapter = null;
  47. }
  48. public function testSerializeNull()
  49. {
  50. $value = null;
  51. $expected = 'N.';
  52. $data = $this->_adapter->serialize($value);
  53. $this->assertEquals($expected, $data);
  54. }
  55. public function testSerializeTrue()
  56. {
  57. $value = true;
  58. $expected = "I01\r\n.";
  59. $data = $this->_adapter->serialize($value);
  60. $this->assertEquals($expected, $data);
  61. }
  62. public function testSerializeFalse()
  63. {
  64. $value = false;
  65. $expected = "I00\r\n.";
  66. $data = $this->_adapter->serialize($value);
  67. $this->assertEquals($expected, $data);
  68. }
  69. public function testSerializeBinInt1()
  70. {
  71. $value = 255;
  72. $expected = "K\xff.";
  73. $data = $this->_adapter->serialize($value);
  74. $this->assertEquals($expected, $data);
  75. }
  76. public function testSerializeBinInt2()
  77. {
  78. $value = 256;
  79. $expected = "M\x00\x01.";
  80. $data = $this->_adapter->serialize($value);
  81. $this->assertEquals($expected, $data);
  82. }
  83. public function testSerializeBinInt()
  84. {
  85. $value = -2;
  86. $expected = "J\xfe\xff\xff\xff.";
  87. $data = $this->_adapter->serialize($value);
  88. $this->assertEquals($expected, $data);
  89. }
  90. public function testSerializeBinFloat()
  91. {
  92. $value = -12345.6789;
  93. $expected = "G\xc0\xc8\x1c\xd6\xe6\x31\xf8\xa1.";
  94. $data = $this->_adapter->serialize($value);
  95. $this->assertEquals($expected, $data);
  96. }
  97. public function testSerializeShortBinString()
  98. {
  99. $value = 'test';
  100. $expected = "U\x04test"
  101. . "q\x00.";
  102. $data = $this->_adapter->serialize($value);
  103. $this->assertEquals($expected, $data);
  104. }
  105. public function testSerializeBinString()
  106. {
  107. $value = "0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789"
  108. . "0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789"
  109. . "01234567890123456789012345678901234567890123456789012345";
  110. $expected = "T\x00\x01\x00\x00"
  111. . "0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789"
  112. . "0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789"
  113. . "01234567890123456789012345678901234567890123456789012345"
  114. . "q\x00.";
  115. $data = $this->_adapter->serialize($value);
  116. $this->assertEquals($expected, $data);
  117. }
  118. }