MediaWiki  REL1_24
MWMessagePackTest.php
Go to the documentation of this file.
00001 <?php
00006 class MWMessagePackTest extends MediaWikiTestCase {
00007 
00016     public static function providePacks() {
00017         $tests = array(
00018             array( 'nil', null, 'c0' ),
00019             array( 'bool', true, 'c3' ),
00020             array( 'bool', false, 'c2' ),
00021             array( 'positive fixnum', 0, '00' ),
00022             array( 'positive fixnum', 1, '01' ),
00023             array( 'positive fixnum', 5, '05' ),
00024             array( 'positive fixnum', 35, '23' ),
00025             array( 'uint 8', 128, 'cc80' ),
00026             array( 'uint 16', 1000, 'cd03e8' ),
00027             array( 'uint 32', 100000, 'ce000186a0' ),
00028             array( 'negative fixnum', -1, 'ff' ),
00029             array( 'negative fixnum', -2, 'fe' ),
00030             array( 'int 8', -128, 'd080' ),
00031             array( 'int 8', -35, 'd0dd' ),
00032             array( 'int 16', -1000, 'd1fc18' ),
00033             array( 'int 32', -100000, 'd2fffe7960' ),
00034             array( 'double', 0.1, 'cb3fb999999999999a' ),
00035             array( 'double', 1.1, 'cb3ff199999999999a' ),
00036             array( 'double', 123.456, 'cb405edd2f1a9fbe77' ),
00037             array( 'fix raw', '', 'a0' ),
00038             array( 'fix raw', 'foobar', 'a6666f6f626172' ),
00039             array(
00040                 'raw 16',
00041                 'Lorem ipsum dolor sit amet amet.',
00042                 'da00204c6f72656d20697073756d20646f6c6f722073697420616d657420616d65742e'
00043             ),
00044             array(
00045                 'fix array',
00046                 array( 'abc', 'def', 'ghi' ),
00047                 '93a3616263a3646566a3676869'
00048             ),
00049             array(
00050                 'fix map',
00051                 array( 'one' => 1, 'two' => 2 ),
00052                 '82a36f6e6501a374776f02'
00053             ),
00054         );
00055 
00056         if ( PHP_INT_SIZE > 4 ) {
00057             $tests[] = array( 'uint 64', 10000000000, 'cf00000002540be400' );
00058             $tests[] = array( 'int 64', -10000000000, 'd3fffffffdabf41c00' );
00059             $tests[] = array( 'int 64', -223372036854775807, 'd3fce66c50e2840001' );
00060             $tests[] = array( 'int 64', -9223372036854775807, 'd38000000000000001' );
00061         }
00062 
00063         return $tests;
00064     }
00065 
00071     public function testPack( $type, $value, $expected ) {
00072         $actual = bin2hex( MWMessagePack::pack( $value ) );
00073         $this->assertEquals( $expected, $actual, $type );
00074     }
00075 }