public function testDecode()
 {
     $test_data = array('0:0:' => false, 'ie' => false, 'i341foo382e' => false, 'i4e' => 4, 'i0e' => 0, 'i123456789e' => 123456789, 'i-10e' => -10, 'i-0e' => false, 'i123' => false, '' => false, 'i6easd' => false, '35208734823ljdahflajhdf' => false, '2:abfdjslhfld' => false, '0:' => '', '3:abc' => 'abc', '10:1234567890' => '1234567890', '02:xy' => false, 'l' => false, 'le' => array(), 'leanfdldjfh' => false, 'l0:0:0:e' => array('', '', ''), 'relwjhrlewjh' => false, 'li1ei2ei3ee' => array(1, 2, 3), 'l3:asd2:xye' => array('asd', 'xy'), 'll5:Alice3:Bobeli2ei3eee' => array(array('Alice', 'Bob'), array(2, 3)), 'd' => false, 'defoobar' => false, 'de' => array(), 'd1:a0:e' => array('a' => ''), 'd3:agei25e4:eyes4:bluee' => array('age' => 25, 'eyes' => 'blue'), 'd8:spam.mp3d6:author5:Alice6:lengthi100000eee' => array('spam.mp3' => array('author' => 'Alice', 'length' => 100000)), 'd3:fooe' => false, 'di1e0:e' => false, 'd1:b0:1:a0:e' => false, 'd1:a0:1:a0:e' => false, 'i03e' => false, 'l01:ae' => false, '9999:x' => false, 'l0:' => false, 'd0:0:' => false, 'd0:' => false, '00:' => false, 'l-3:e' => false, 'i-03e' => false, 'di0e0:e' => false, 'd8:announceldi0e0:eee' => false, 'd8:announcedi0e0:e18:azureus_propertiesi0ee' => false);
     // Thanks to IsoHunt.com for the last 3 testcases of bad data seen in their system.
     $File_Bittorrent2_Decode = new File_Bittorrent2_Decode();
     ini_set('mbstring.internal_encoding', 'ASCII');
     foreach ($test_data as $ti => $to) {
         if ($to === false) {
             try {
                 $File_Bittorrent2_Decode->decode($ti);
                 $this->fail('File_Bittorrent2 successfully decoded invalid data.');
             } catch (File_Bittorrent2_Exception $E) {
                 if ($E->getCode() != File_Bittorrent2_Exception::decode) {
                     throw $E;
                 }
             }
         } else {
             $this->assertEquals($to, $File_Bittorrent2_Decode->decode($ti));
         }
     }
 }
Ejemplo n.º 2
0
 public function testMakePrivateTorrent()
 {
     $Torrent = new File_Bittorrent2_MakeTorrent(__FILE__);
     $Torrent->setAnnounce('http://example.com/');
     $Torrent->setIsPrivate(true);
     $tfile = tempnam('./', __CLASS__);
     $bemetainfo = $Torrent->buildTorrent();
     file_put_contents($tfile, $bemetainfo);
     $Decode = new File_Bittorrent2_Decode();
     $Decode->decodeFile($tfile);
     $metainfo = $Decode->decode($bemetainfo);
     unlink($tfile);
     $this->assertTrue($Decode->isPrivate());
     $this->assertTrue($metainfo['info']['private'] === 1);
 }
Ejemplo n.º 3
0
 public function testAnnounceList()
 {
     $MakeTorrent = new File_Bittorrent2_MakeTorrent(self::$torrent);
     // Set the announce URL
     $MakeTorrent->setAnnounce('http://www.example.org');
     // Set the comment
     $MakeTorrent->setComment('Hello World!');
     // Set the piece length (in KB)
     $MakeTorrent->setPieceLength(256);
     // Build the torrent
     $metainfo = $MakeTorrent->buildTorrent();
     $Decode = new File_Bittorrent2_Decode();
     $info = $Decode->decode($metainfo);
     $this->assertEquals(count($info['info']['files']), 3);
     $files = array();
     foreach ($info['info']['files'] as $k => $v) {
         $files[] = $v['path'][0];
     }
     sort($files);
     $expected = array('1.txt', '2.txt', '3.txt');
     $this->assertEquals($expected, $files);
 }
Ejemplo n.º 4
0
<?php

/**
 * Test case for Bug #3970
 *
 * @see http://pear.php.net/bugs/bug.php?id=3970
 *
 * @author Markus Tacker <*****@*****.**>
 * @version $Id$
 * @package File_Bittorrent2
 * @subpackage Bugs
 */
require_once '../File/Bittorrent2/Encode.php';
require_once '../File/Bittorrent2/Decode.php';
$Decoder = new File_Bittorrent2_Decode();
$Encoder = new File_Bittorrent2_Encode();
$torrent = $Decoder->decode(file_get_contents('../freebsd.torrent'));
$info_encoded = $Encoder->encode($torrent);
$decoded_info_encoded = $Decoder->decode($info_encoded);
var_dump($torrent['info']['piece length']);
var_dump($decoded_info_encoded['info']['piece length']);
Ejemplo n.º 5
0
 * @author Justin "nagash" Jones <j dot nagash at gmail dot com>
 * @version $Id$
 * @package File_Bittorrent2
 * @subpackage Bugs
 */
require_once '../File/Bittorrent2/Encode.php';
require_once '../File/Bittorrent2/Decode.php';
$decoder = new File_Bittorrent2_Decode();
$encoder = new File_Bittorrent2_Encode();
error_reporting(E_ALL);
$data = array('broken' => null, 'bit' => 'torrent');
echo '<pre>';
echo 'The data array:' . "\n";
print_r($data);
$encode1 = $encoder->encode_array($data);
$decode1 = $decoder->decode($encode1);
echo "\n" . 'First decode:' . "\n";
print_r($decode1);
// Works fine!
// If you add and remove and change these things, your results will vary.
// Sometimes I just got an empty Array, other times I got data in the wrong keys.
// And for the worst times, it looped indefinately, but I couldn't reproduce that
// with this data - see below for an example.'
$decode1['bit'] = 'testing';
$decode1['bitlength'] = strlen($decode1['bit']);
$decode1['field'] = 'something';
$decode1['other'] = 'whee';
echo "\n" . 'New data to encode:' . "\n";
print_r($decode1);
$encode2 = $encoder->encode_array($decode1);
$decode2 = $decoder->decode($encode2);
Ejemplo n.º 6
0
*
* @author Markus Tacker <*****@*****.**>
* @version $Id$
*/
/**
* Include class
*/
require_once 'File/Bittorrent2/Encode.php';
require_once 'File/Bittorrent2/Decode.php';
$File_Bittorrent2_Decode = new File_Bittorrent2_Decode();
$File_Bittorrent2_Encode = new File_Bittorrent2_Encode();
// Encoding vars
echo "Encoding integers\n";
$encodedInt = $File_Bittorrent2_Encode->encode(10);
var_dump($encodedInt);
var_dump($File_Bittorrent2_Decode->decode($encodedInt));
echo "Encoding strings\n";
$encodedStr = $File_Bittorrent2_Encode->encode('This is a string.');
var_dump($encodedStr);
var_dump($File_Bittorrent2_Decode->decode($encodedStr));
echo "Encoding arrays as lists\n";
$encodedList = $File_Bittorrent2_Encode->encode(array('Banana', 'Apple', 'Cherry'));
var_dump($encodedList);
var_dump($File_Bittorrent2_Decode->decode($encodedList));
echo "Encoding arrays as dictionaries\n";
$encodedDict = $File_Bittorrent2_Encode->encode(array('fruits' => array('Banana', 'Apple', 'Cherry', 'subarray' => array(1, 2, 3)), 'ints' => array(1, 2, 3), 'count' => 3));
var_dump($encodedDict);
print_r($File_Bittorrent2_Decode->decode($encodedDict));
// Decode a file
print_r($File_Bittorrent2_Decode->decodeFile('install-x86-universal-2005.0.iso.torrent'));
/* Output of decode