Update tests

git-svn-id: http://php-reader.googlecode.com/svn/trunk@179 51a70ab9-7547-0410-9469-37e369ee0574
This commit is contained in:
svollbehr
2010-03-09 14:36:37 +00:00
parent b3534b1ed7
commit c685291088
6 changed files with 353 additions and 536 deletions

View File

@@ -1,6 +1,6 @@
#
# PHP Reader Library
#
#
# Copyright (c) 2008 The PHP Reader Project Workgroup. All rights reserved.
#
# Redistribution and use in source and binary forms, with or without

View File

@@ -36,13 +36,13 @@
*/
/**#@+ @ignore */
require_once("PHPUnit/Framework.php");
require_once("PHPUnit/TextUI/TestRunner.php");
require_once 'PHPUnit/Framework.php';
require_once 'PHPUnit/TextUI/TestRunner.php';
ini_set("include_path", ini_get("include_path") . PATH_SEPARATOR . "../src/");
ini_set("memory_limit", "16M");
ini_set('include_path', ini_get('include_path') . PATH_SEPARATOR . '../src/');
ini_set('memory_limit', '32M');
$suite = new PHPUnit_Framework_TestSuite("PHP Reader");
$suite = new PHPUnit_Framework_TestSuite('PHP Reader');
$dir = opendir(dirname(__FILE__));
while (($file = readdir($dir)) !== false) {

View File

@@ -36,8 +36,8 @@
*/
/**#@+ @ignore */
require_once("PHPUnit/Framework.php");
require_once("Reader.php");
require_once 'PHPUnit/Framework.php';
require_once 'Zend/Io/Reader.php';
/**#@-*/
/**
@@ -49,20 +49,20 @@ require_once("Reader.php");
* @author Sven Vollbehr <svollbehr@gmail.com>
* @copyright Copyright (c) 2008 The PHP Reader Project Workgroup
* @license http://code.google.com/p/php-reader/wiki/License New BSD License
* @version $Rev$
* @version $Id$
*/
final class TestID3Frame extends PHPUnit_Framework_TestCase
{
const INITIALIZE = 1;
const DRYRUN = 2;
const RUN = 3;
private $testText = "abcdefghijklmnopqrstuvwxyzåäö1234567890!@#\$%^&*()-";
private $testLink = "http://www.abcdefghijklmnopqrstuvwxyz.com.xyz/qwerty.php?asdf=1234&zxcv=%20";
private $testDate = "20070707";
private $testCurrency = "AUD";
private $testIdentifier = "TEST";
private $testPrice = "169.12";
private $testLink = 'http://www.abcdefghijklmnopqrstuvwxyz.com.xyz/qwerty.php?asdf=1234&zxcv=%20';
private $testDate = '20070707';
private $testCurrency = 'AUD';
private $testIdentifier = 'TEST';
private $testPrice = '169.12';
private $testInt8 = -0x7a;
private $testInt16 = -0x7aff;
private $testInt24 = 0x7affca;
@@ -78,15 +78,15 @@ final class TestID3Frame extends PHPUnit_Framework_TestCase
public static function provider()
{
/* Ignore WIP frames */
$ignore = array("ASPI.php", "MLLT.php");
$ignore = array('Aspi.php', 'Mllt.php');
/* Load all frames */
$dir = opendir("../src/ID3/Frame");
$dir = opendir('../src/Zend/Media/Id3/Frame');
while (($file = readdir($dir)) !== false)
if (preg_match("/^.+\.php$/", $file) && !in_array($file, $ignore))
require_once("ID3/Frame/" . $file);
require_once('Zend/Media/Id3/Frame/' . $file);
foreach (get_declared_classes() as $class)
if (strpos($class, "ID3_Frame_") === 0)
if (strpos($class, "Zend_Media_Id3_Frame_") === 0)
$identifiers[] = substr($class, 10);
closedir($dir);
@@ -94,18 +94,20 @@ final class TestID3Frame extends PHPUnit_Framework_TestCase
$tests = array();
foreach ($identifiers as $identifier)
{
if (!method_exists("TestID3Frame", "frame" . $identifier . "0"))
if (!method_exists('TestID3Frame', 'frame' . $identifier . '0'))
continue; // skip if no handlers registered
$class = "ID3_Frame_" . $identifier;
$class = 'Zend_Media_Id3_Frame_' . $identifier;
$encodings = $languages = $timings = array(null);
if (in_array("ID3_Encoding", class_implements($class)))
array_push($encodings, ID3_Encoding::ISO88591, ID3_Encoding::UTF16,
ID3_Encoding::UTF16BE, ID3_Encoding::UTF8);
if (in_array("ID3_Language", class_implements($class)))
array_push($languages, "eng", "und");
if (in_array("ID3_Timing", class_implements($class)))
array_push($timings, ID3_Timing::MPEG_FRAMES, ID3_Timing::MILLISECONDS);
if (in_array('Zend_Media_Id3_Encoding', class_implements($class)))
array_push($encodings, Zend_Media_Id3_Encoding::ISO88591,
Zend_Media_Id3_Encoding::UTF16, Zend_Media_Id3_Encoding::UTF16BE,
Zend_Media_Id3_Encoding::UTF8);
if (in_array('Zend_Media_Id3_Language', class_implements($class)))
array_push($languages, 'eng', 'und');
if (in_array('Zend_Media_Id3_Timing', class_implements($class)))
array_push($timings, Zend_Media_Id3_Timing::MPEG_FRAMES,
Zend_Media_Id3_Timing::MILLISECONDS);
foreach ($encodings as $encoding)
foreach ($languages as $language)
@@ -126,8 +128,8 @@ final class TestID3Frame extends PHPUnit_Framework_TestCase
* string and testing for a final time.
*
* @param string $identifier The frame identifier.
* @param integer $encoding The {@link ID3_Encoding text encoding} for strings
* in this frame.
* @param integer $encoding The {@link Zend_Media_Id3_Encoding text encoding}
* for strings in this frame.
* @param string $language The language code.
* @param integer $timing The timing format.
*
@@ -136,7 +138,7 @@ final class TestID3Frame extends PHPUnit_Framework_TestCase
public function testFrame($identifier, $encoding, $language, $timing)
{
/* Iterate through all test case functions for this frame identifier */
$class = "ID3_Frame_" . $identifier;
$class = 'Zend_Media_Id3_Frame_' . $identifier;
$test = 0;
while (method_exists($this, $method = "frame" . $identifier . $test++)) {
@@ -148,21 +150,21 @@ final class TestID3Frame extends PHPUnit_Framework_TestCase
$frame, self::DRYRUN, $encoding, $language, $timing);
if (isset($encoding)) {
$this->assertTrue(method_exists($frame, "setEncoding"));
$this->assertTrue(method_exists($frame, 'setEncoding'));
$frame->setEncoding($encoding);
$this->assertTrue(method_exists($frame, "getEncoding"));
$this->assertTrue(method_exists($frame, 'getEncoding'));
$this->assertEquals($encoding, $frame->getEncoding());
}
if (isset($language)) {
$this->assertTrue(method_exists($frame, "setLanguage"));
$this->assertTrue(method_exists($frame, 'setLanguage'));
$frame->setLanguage($language);
$this->assertTrue(method_exists($frame, "getLanguage"));
$this->assertTrue(method_exists($frame, 'getLanguage'));
$this->assertEquals($language, $frame->getLanguage());
}
if (isset($timing)) {
$this->assertTrue(method_exists($frame, "setFormat"));
$this->assertTrue(method_exists($frame, 'setFormat'));
$frame->setFormat($timing);
$this->assertTrue(method_exists($frame, "getFormat"));
$this->assertTrue(method_exists($frame, 'getFormat'));
$this->assertEquals($timing, $frame->getFormat());
}
@@ -170,13 +172,13 @@ final class TestID3Frame extends PHPUnit_Framework_TestCase
/* Convert to string representation and store in an in-memory buffer */
if ($i > 0)
$existing = $data;
$length = strlen($data = "" . $frame);
$this->assertTrue(($fd = fopen("php://temp", "r+b")) !== false);
$length = strlen($data = '' . $frame);
$this->assertTrue(($fd = fopen('php://temp', 'r+b')) !== false);
$this->assertEquals($length, fwrite($fd, $data, $length));
$this->assertTrue(rewind($fd));
/* Construct a frame using the reader and verify */
$frame = new $class($reader = new Reader($fd));
$frame = new $class($reader = new Zend_Io_Reader($fd));
call_user_func(array($this, $method),
$frame, self::RUN, $encoding, $language, $timing);
if (isset($language))
@@ -190,9 +192,9 @@ final class TestID3Frame extends PHPUnit_Framework_TestCase
/**
* The first AENC frame test.
*
* @param ID3_Frame_AENC $frame The frame to test.
* @param Zend_Media_Id3_Frame_AENC $frame The frame to test.
* @param boolean $action The requested action.
* @param integer $encoding The {@link ID3_Encoding text encoding} for strings
* @param integer $encoding The {@link Zend_Media_Id3_Encoding text encoding} for strings
* in this frame.
* @param string $language The language code.
* @param integer $timing The timing format.
@@ -221,9 +223,9 @@ final class TestID3Frame extends PHPUnit_Framework_TestCase
/**
* The first APIC frame test.
*
* @param ID3_Frame_APIC $frame The frame to test.
* @param Zend_Media_Id3_Frame_APIC $frame The frame to test.
* @param boolean $action The requested action.
* @param integer $encoding The {@link ID3_Encoding text encoding} for strings
* @param integer $encoding The {@link Zend_Media_Id3_Encoding text encoding} for strings
* in this frame.
* @param string $language The language code.
* @param integer $timing The timing format.
@@ -257,9 +259,9 @@ final class TestID3Frame extends PHPUnit_Framework_TestCase
/**
* The first COMM frame test.
*
* @param ID3_Frame_COMM $frame The frame to test.
* @param Zend_Media_Id3_Frame_COMM $frame The frame to test.
* @param boolean $action The requested action.
* @param integer $encoding The {@link ID3_Encoding text encoding} for strings
* @param integer $encoding The {@link Zend_Media_Id3_Encoding text encoding} for strings
* in this frame.
* @param string $language The language code.
* @param integer $timing The timing format.
@@ -287,9 +289,9 @@ final class TestID3Frame extends PHPUnit_Framework_TestCase
/**
* The first COMR frame test.
*
* @param ID3_Frame_COMR $frame The frame to test.
* @param Zend_Media_Id3_Frame_COMR $frame The frame to test.
* @param boolean $action The requested action.
* @param integer $encoding The {@link ID3_Encoding text encoding} for strings
* @param integer $encoding The {@link Zend_Media_Id3_Encoding text encoding} for strings
* in this frame.
* @param string $language The language code.
* @param integer $timing The timing format.
@@ -340,9 +342,9 @@ final class TestID3Frame extends PHPUnit_Framework_TestCase
/**
* The first ENCR frame test.
*
* @param ID3_Frame_ENCR $frame The frame to test.
* @param Zend_Media_Id3_Frame_ENCR $frame The frame to test.
* @param boolean $action The requested action.
* @param integer $encoding The {@link ID3_Encoding text encoding} for strings
* @param integer $encoding The {@link Zend_Media_Id3_Encoding text encoding} for strings
* in this frame.
* @param string $language The language code.
* @param integer $timing The timing format.
@@ -368,9 +370,9 @@ final class TestID3Frame extends PHPUnit_Framework_TestCase
/**
* The first EQU2 frame test.
*
* @param ID3_Frame_EQU2 $frame The frame to test.
* @param Zend_Media_Id3_Frame_EQU2 $frame The frame to test.
* @param boolean $action The requested action.
* @param integer $encoding The {@link ID3_Encoding text encoding} for strings
* @param integer $encoding The {@link Zend_Media_Id3_Encoding text encoding} for strings
* in this frame.
* @param string $language The language code.
* @param integer $timing The timing format.
@@ -404,9 +406,9 @@ final class TestID3Frame extends PHPUnit_Framework_TestCase
/**
* The first EQUA frame test.
*
* @param ID3_Frame_EQUA $frame The frame to test.
* @param Zend_Media_Id3_Frame_EQUA $frame The frame to test.
* @param boolean $action The requested action.
* @param integer $encoding The {@link ID3_Encoding text encoding} for strings
* @param integer $encoding The {@link Zend_Media_Id3_Encoding text encoding} for strings
* in this frame.
* @param string $language The language code.
* @param integer $timing The timing format.
@@ -434,9 +436,9 @@ final class TestID3Frame extends PHPUnit_Framework_TestCase
/**
* The first ETCO frame test.
*
* @param ID3_Frame_ETCO $frame The frame to test.
* @param Zend_Media_Id3_Frame_ETCO $frame The frame to test.
* @param boolean $action The requested action.
* @param integer $encoding The {@link ID3_Encoding text encoding} for strings
* @param integer $encoding The {@link Zend_Media_Id3_Encoding text encoding} for strings
* in this frame.
* @param string $language The language code.
* @param integer $timing The timing format.
@@ -444,13 +446,13 @@ final class TestID3Frame extends PHPUnit_Framework_TestCase
private function frameETCO0
(&$frame, $action, $encoding, $language, $timing)
{
$events[0] = array_search("Intro end", ID3_Frame_ETCO::$types);
$events[0xFFFF] = array_search("Verse start", ID3_Frame_ETCO::$types);
$events[0xFFFFF] = array_search("Verse end", ID3_Frame_ETCO::$types);
$events[0] = array_search('Intro end', Zend_Media_Id3_Frame_ETCO::$types);
$events[0xFFFF] = array_search('Verse start', Zend_Media_Id3_Frame_ETCO::$types);
$events[0xFFFFF] = array_search('Verse end', Zend_Media_Id3_Frame_ETCO::$types);
$events[0xFFFFFF] = array_search
("Audio end (start of silence)", ID3_Frame_ETCO::$types);
('Audio end (start of silence)', Zend_Media_Id3_Frame_ETCO::$types);
$events[0xFFFFFFFF] = array_search
("Audio file ends", ID3_Frame_ETCO::$types);
('Audio file ends', Zend_Media_Id3_Frame_ETCO::$types);
if ($action == self::INITIALIZE)
$frame->setEvents($events);
@@ -461,9 +463,9 @@ final class TestID3Frame extends PHPUnit_Framework_TestCase
/**
* The first GEOB frame test.
*
* @param ID3_Frame_GEOB $frame The frame to test.
* @param Zend_Media_Id3_Frame_GEOB $frame The frame to test.
* @param boolean $action The requested action.
* @param integer $encoding The {@link ID3_Encoding text encoding} for strings
* @param integer $encoding The {@link Zend_Media_Id3_Encoding text encoding} for strings
* in this frame.
* @param string $language The language code.
* @param integer $timing The timing format.
@@ -497,9 +499,9 @@ final class TestID3Frame extends PHPUnit_Framework_TestCase
/**
* The first GRID frame test.
*
* @param ID3_Frame_GRID $frame The frame to test.
* @param Zend_Media_Id3_Frame_GRID $frame The frame to test.
* @param boolean $action The requested action.
* @param integer $encoding The {@link ID3_Encoding text encoding} for strings
* @param integer $encoding The {@link Zend_Media_Id3_Encoding text encoding} for strings
* in this frame.
* @param string $language The language code.
* @param integer $timing The timing format.
@@ -525,9 +527,9 @@ final class TestID3Frame extends PHPUnit_Framework_TestCase
/**
* The first IPLS frame test.
*
* @param ID3_Frame_IPLS $frame The frame to test.
* @param Zend_Media_Id3_Frame_IPLS $frame The frame to test.
* @param boolean $action The requested action.
* @param integer $encoding The {@link ID3_Encoding text encoding} for strings
* @param integer $encoding The {@link Zend_Media_Id3_Encoding text encoding} for strings
* in this frame.
* @param string $language The language code.
* @param integer $timing The timing format.
@@ -559,9 +561,9 @@ final class TestID3Frame extends PHPUnit_Framework_TestCase
/**
* The first LINK frame test.
*
* @param ID3_Frame_LINK $frame The frame to test.
* @param Zend_Media_Id3_Frame_LINK $frame The frame to test.
* @param boolean $action The requested action.
* @param integer $encoding The {@link ID3_Encoding text encoding} for strings
* @param integer $encoding The {@link Zend_Media_Id3_Encoding text encoding} for strings
* in this frame.
* @param string $language The language code.
* @param integer $timing The timing format.
@@ -587,9 +589,9 @@ final class TestID3Frame extends PHPUnit_Framework_TestCase
/**
* The first MCDI frame test.
*
* @param ID3_Frame_MCDI $frame The frame to test.
* @param Zend_Media_Id3_Frame_MCDI $frame The frame to test.
* @param boolean $action The requested action.
* @param integer $encoding The {@link ID3_Encoding text encoding} for strings
* @param integer $encoding The {@link Zend_Media_Id3_Encoding text encoding} for strings
* in this frame.
* @param string $language The language code.
* @param integer $timing The timing format.
@@ -608,9 +610,9 @@ final class TestID3Frame extends PHPUnit_Framework_TestCase
/**
* The first OWNE frame test.
*
* @param ID3_Frame_OWNE $frame The frame to test.
* @param Zend_Media_Id3_Frame_OWNE $frame The frame to test.
* @param boolean $action The requested action.
* @param integer $encoding The {@link ID3_Encoding text encoding} for strings
* @param integer $encoding The {@link Zend_Media_Id3_Encoding text encoding} for strings
* in this frame.
* @param string $language The language code.
* @param integer $timing The timing format.
@@ -642,9 +644,9 @@ final class TestID3Frame extends PHPUnit_Framework_TestCase
/**
* The first PCNT frame test.
*
* @param ID3_Frame_PCNT $frame The frame to test.
* @param Zend_Media_Id3_Frame_PCNT $frame The frame to test.
* @param boolean $action The requested action.
* @param integer $encoding The {@link ID3_Encoding text encoding} for strings
* @param integer $encoding The {@link Zend_Media_Id3_Encoding text encoding} for strings
* in this frame.
* @param string $language The language code.
* @param integer $timing The timing format.
@@ -668,9 +670,9 @@ final class TestID3Frame extends PHPUnit_Framework_TestCase
/**
* The first POPM frame test.
*
* @param ID3_Frame_POPM $frame The frame to test.
* @param Zend_Media_Id3_Frame_POPM $frame The frame to test.
* @param boolean $action The requested action.
* @param integer $encoding The {@link ID3_Encoding text encoding} for strings
* @param integer $encoding The {@link Zend_Media_Id3_Encoding text encoding} for strings
* in this frame.
* @param string $language The language code.
* @param integer $timing The timing format.
@@ -696,9 +698,9 @@ final class TestID3Frame extends PHPUnit_Framework_TestCase
/**
* The first POSS frame test.
*
* @param ID3_Frame_POSS $frame The frame to test.
* @param Zend_Media_Id3_Frame_POSS $frame The frame to test.
* @param boolean $action The requested action.
* @param integer $encoding The {@link ID3_Encoding text encoding} for strings
* @param integer $encoding The {@link Zend_Media_Id3_Encoding text encoding} for strings
* in this frame.
* @param string $language The language code.
* @param integer $timing The timing format.
@@ -717,9 +719,9 @@ final class TestID3Frame extends PHPUnit_Framework_TestCase
/**
* The first PRIV frame test.
*
* @param ID3_Frame_PRIV $frame The frame to test.
* @param Zend_Media_Id3_Frame_PRIV $frame The frame to test.
* @param boolean $action The requested action.
* @param integer $encoding The {@link ID3_Encoding text encoding} for strings
* @param integer $encoding The {@link Zend_Media_Id3_Encoding text encoding} for strings
* in this frame.
* @param string $language The language code.
* @param integer $timing The timing format.
@@ -742,9 +744,9 @@ final class TestID3Frame extends PHPUnit_Framework_TestCase
/**
* The first RBUF frame test.
*
* @param ID3_Frame_RBUF $frame The frame to test.
* @param Zend_Media_Id3_Frame_RBUF $frame The frame to test.
* @param boolean $action The requested action.
* @param integer $encoding The {@link ID3_Encoding text encoding} for strings
* @param integer $encoding The {@link Zend_Media_Id3_Encoding text encoding} for strings
* in this frame.
* @param string $language The language code.
* @param integer $timing The timing format.
@@ -770,9 +772,9 @@ final class TestID3Frame extends PHPUnit_Framework_TestCase
/**
* The first RVA2 frame test.
*
* @param ID3_Frame_RVA2 $frame The frame to test.
* @param Zend_Media_Id3_Frame_RVA2 $frame The frame to test.
* @param boolean $action The requested action.
* @param integer $encoding The {@link ID3_Encoding text encoding} for strings
* @param integer $encoding The {@link Zend_Media_Id3_Encoding text encoding} for strings
* in this frame.
* @param string $language The language code.
* @param integer $timing The timing format.
@@ -781,33 +783,33 @@ final class TestID3Frame extends PHPUnit_Framework_TestCase
(&$frame, $action, $encoding, $language, $timing)
{
$device = $this->testText;
$adjustments[0] = array(ID3_Frame_RVA2::channelType => 0,
ID3_Frame_RVA2::volumeAdjustment => -32767.0 / 512.0,
ID3_Frame_RVA2::peakVolume => 0x0);
$adjustments[1] = array(ID3_Frame_RVA2::channelType => 1,
ID3_Frame_RVA2::volumeAdjustment => -8191.0 / 512.0,
ID3_Frame_RVA2::peakVolume => 0x7f);
$adjustments[2] = array(ID3_Frame_RVA2::channelType => 2,
ID3_Frame_RVA2::volumeAdjustment => -2047.0 / 512.0,
ID3_Frame_RVA2::peakVolume => 0xff);
$adjustments[3] = array(ID3_Frame_RVA2::channelType => 3,
ID3_Frame_RVA2::volumeAdjustment => -1.0,
ID3_Frame_RVA2::peakVolume => 0x7fff);
$adjustments[4] = array(ID3_Frame_RVA2::channelType => 4,
ID3_Frame_RVA2::volumeAdjustment => 0.0,
ID3_Frame_RVA2::peakVolume => 0xffff);
$adjustments[5] = array(ID3_Frame_RVA2::channelType => 5,
ID3_Frame_RVA2::volumeAdjustment => 1.0,
ID3_Frame_RVA2::peakVolume => 0x7fffff);
$adjustments[6] = array(ID3_Frame_RVA2::channelType => 6,
ID3_Frame_RVA2::volumeAdjustment => 2047.0 / 512.0,
ID3_Frame_RVA2::peakVolume => 0xffffff);
$adjustments[7] = array(ID3_Frame_RVA2::channelType => 7,
ID3_Frame_RVA2::volumeAdjustment => 8191.0 / 512.0,
ID3_Frame_RVA2::peakVolume => 0x7fffffff);
$adjustments[8] = array(ID3_Frame_RVA2::channelType => 8,
ID3_Frame_RVA2::volumeAdjustment => 32767.0 / 512.0,
ID3_Frame_RVA2::peakVolume => 0xffffffff);
$adjustments[0] = array(Zend_Media_Id3_Frame_RVA2::channelType => 0,
Zend_Media_Id3_Frame_RVA2::volumeAdjustment => -32767.0 / 512.0,
Zend_Media_Id3_Frame_RVA2::peakVolume => 0x0);
$adjustments[1] = array(Zend_Media_Id3_Frame_RVA2::channelType => 1,
Zend_Media_Id3_Frame_RVA2::volumeAdjustment => -8191.0 / 512.0,
Zend_Media_Id3_Frame_RVA2::peakVolume => 0x7f);
$adjustments[2] = array(Zend_Media_Id3_Frame_RVA2::channelType => 2,
Zend_Media_Id3_Frame_RVA2::volumeAdjustment => -2047.0 / 512.0,
Zend_Media_Id3_Frame_RVA2::peakVolume => 0xff);
$adjustments[3] = array(Zend_Media_Id3_Frame_RVA2::channelType => 3,
Zend_Media_Id3_Frame_RVA2::volumeAdjustment => -1.0,
Zend_Media_Id3_Frame_RVA2::peakVolume => 0x7fff);
$adjustments[4] = array(Zend_Media_Id3_Frame_RVA2::channelType => 4,
Zend_Media_Id3_Frame_RVA2::volumeAdjustment => 0.0,
Zend_Media_Id3_Frame_RVA2::peakVolume => 0xffff);
$adjustments[5] = array(Zend_Media_Id3_Frame_RVA2::channelType => 5,
Zend_Media_Id3_Frame_RVA2::volumeAdjustment => 1.0,
Zend_Media_Id3_Frame_RVA2::peakVolume => 0x7fffff);
$adjustments[6] = array(Zend_Media_Id3_Frame_RVA2::channelType => 6,
Zend_Media_Id3_Frame_RVA2::volumeAdjustment => 2047.0 / 512.0,
Zend_Media_Id3_Frame_RVA2::peakVolume => 0xffffff);
$adjustments[7] = array(Zend_Media_Id3_Frame_RVA2::channelType => 7,
Zend_Media_Id3_Frame_RVA2::volumeAdjustment => 8191.0 / 512.0,
Zend_Media_Id3_Frame_RVA2::peakVolume => 0x7fffffff);
$adjustments[8] = array(Zend_Media_Id3_Frame_RVA2::channelType => 8,
Zend_Media_Id3_Frame_RVA2::volumeAdjustment => 32767.0 / 512.0,
Zend_Media_Id3_Frame_RVA2::peakVolume => 0xffffffff);
if ($action == self::INITIALIZE) {
$frame->setDevice($device);
@@ -821,9 +823,9 @@ final class TestID3Frame extends PHPUnit_Framework_TestCase
/**
* The first RVAD frame test.
*
* @param ID3_Frame_RVAD $frame The frame to test.
* @param Zend_Media_Id3_Frame_RVAD $frame The frame to test.
* @param boolean $action The requested action.
* @param integer $encoding The {@link ID3_Encoding text encoding} for strings
* @param integer $encoding The {@link Zend_Media_Id3_Encoding text encoding} for strings
* in this frame.
* @param string $language The language code.
* @param integer $timing The timing format.
@@ -831,10 +833,10 @@ final class TestID3Frame extends PHPUnit_Framework_TestCase
private function frameRVAD0
(&$frame, $action, $encoding, $language, $timing)
{
$adjustments[ID3_Frame_RVAD::right] = -0xffff;
$adjustments[ID3_Frame_RVAD::left] = 0xffff;
$adjustments[ID3_Frame_RVAD::peakRight] = 0xffff;
$adjustments[ID3_Frame_RVAD::peakLeft] = 0xfff;
$adjustments[Zend_Media_Id3_Frame_RVAD::right] = -0xffff;
$adjustments[Zend_Media_Id3_Frame_RVAD::left] = 0xffff;
$adjustments[Zend_Media_Id3_Frame_RVAD::peakRight] = 0xffff;
$adjustments[Zend_Media_Id3_Frame_RVAD::peakLeft] = 0xfff;
if ($action == self::INITIALIZE)
$frame->setAdjustments($adjustments);
@@ -845,9 +847,9 @@ final class TestID3Frame extends PHPUnit_Framework_TestCase
/**
* The second RVAD frame test.
*
* @param ID3_Frame_RVAD $frame The frame to test.
* @param Zend_Media_Id3_Frame_RVAD $frame The frame to test.
* @param boolean $action The requested action.
* @param integer $encoding The {@link ID3_Encoding text encoding} for strings
* @param integer $encoding The {@link Zend_Media_Id3_Encoding text encoding} for strings
* in this frame.
* @param string $language The language code.
* @param integer $timing The timing format.
@@ -855,14 +857,14 @@ final class TestID3Frame extends PHPUnit_Framework_TestCase
private function frameRVAD1
(&$frame, $action, $encoding, $language, $timing)
{
$adjustments[ID3_Frame_RVAD::right] = -0xffff;
$adjustments[ID3_Frame_RVAD::left] = 0xffff;
$adjustments[ID3_Frame_RVAD::peakRight] = 0xffff;
$adjustments[ID3_Frame_RVAD::peakLeft] = 0xfff;
$adjustments[ID3_Frame_RVAD::rightBack] = -0xff;
$adjustments[ID3_Frame_RVAD::leftBack] = 0xff;
$adjustments[ID3_Frame_RVAD::peakRightBack] = 0xff;
$adjustments[ID3_Frame_RVAD::peakLeftBack] = 0xf;
$adjustments[Zend_Media_Id3_Frame_RVAD::right] = -0xffff;
$adjustments[Zend_Media_Id3_Frame_RVAD::left] = 0xffff;
$adjustments[Zend_Media_Id3_Frame_RVAD::peakRight] = 0xffff;
$adjustments[Zend_Media_Id3_Frame_RVAD::peakLeft] = 0xfff;
$adjustments[Zend_Media_Id3_Frame_RVAD::rightBack] = -0xff;
$adjustments[Zend_Media_Id3_Frame_RVAD::leftBack] = 0xff;
$adjustments[Zend_Media_Id3_Frame_RVAD::peakRightBack] = 0xff;
$adjustments[Zend_Media_Id3_Frame_RVAD::peakLeftBack] = 0xf;
if ($action == self::INITIALIZE)
$frame->setAdjustments($adjustments);
@@ -873,9 +875,9 @@ final class TestID3Frame extends PHPUnit_Framework_TestCase
/**
* The third RVAD frame test.
*
* @param ID3_Frame_RVAD $frame The frame to test.
* @param Zend_Media_Id3_Frame_RVAD $frame The frame to test.
* @param boolean $action The requested action.
* @param integer $encoding The {@link ID3_Encoding text encoding} for strings
* @param integer $encoding The {@link Zend_Media_Id3_Encoding text encoding} for strings
* in this frame.
* @param string $language The language code.
* @param integer $timing The timing format.
@@ -883,16 +885,16 @@ final class TestID3Frame extends PHPUnit_Framework_TestCase
private function frameRVAD2
(&$frame, $action, $encoding, $language, $timing)
{
$adjustments[ID3_Frame_RVAD::right] = -0xffff;
$adjustments[ID3_Frame_RVAD::left] = 0xffff;
$adjustments[ID3_Frame_RVAD::peakRight] = 0xffff;
$adjustments[ID3_Frame_RVAD::peakLeft] = 0xfff;
$adjustments[ID3_Frame_RVAD::rightBack] = -0xff;
$adjustments[ID3_Frame_RVAD::leftBack] = 0xff;
$adjustments[ID3_Frame_RVAD::peakRightBack] = 0xff;
$adjustments[ID3_Frame_RVAD::peakLeftBack] = 0xf;
$adjustments[ID3_Frame_RVAD::center] = 0xf;
$adjustments[ID3_Frame_RVAD::peakCenter] = 0x7;
$adjustments[Zend_Media_Id3_Frame_RVAD::right] = -0xffff;
$adjustments[Zend_Media_Id3_Frame_RVAD::left] = 0xffff;
$adjustments[Zend_Media_Id3_Frame_RVAD::peakRight] = 0xffff;
$adjustments[Zend_Media_Id3_Frame_RVAD::peakLeft] = 0xfff;
$adjustments[Zend_Media_Id3_Frame_RVAD::rightBack] = -0xff;
$adjustments[Zend_Media_Id3_Frame_RVAD::leftBack] = 0xff;
$adjustments[Zend_Media_Id3_Frame_RVAD::peakRightBack] = 0xff;
$adjustments[Zend_Media_Id3_Frame_RVAD::peakLeftBack] = 0xf;
$adjustments[Zend_Media_Id3_Frame_RVAD::center] = 0xf;
$adjustments[Zend_Media_Id3_Frame_RVAD::peakCenter] = 0x7;
if ($action == self::INITIALIZE)
$frame->setAdjustments($adjustments);
@@ -903,9 +905,9 @@ final class TestID3Frame extends PHPUnit_Framework_TestCase
/**
* The fourth RVAD frame test.
*
* @param ID3_Frame_RVAD $frame The frame to test.
* @param Zend_Media_Id3_Frame_RVAD $frame The frame to test.
* @param boolean $action The requested action.
* @param integer $encoding The {@link ID3_Encoding text encoding} for strings
* @param integer $encoding The {@link Zend_Media_Id3_Encoding text encoding} for strings
* in this frame.
* @param string $language The language code.
* @param integer $timing The timing format.
@@ -913,18 +915,18 @@ final class TestID3Frame extends PHPUnit_Framework_TestCase
private function frameRVAD3
(&$frame, $action, $encoding, $language, $timing)
{
$adjustments[ID3_Frame_RVAD::right] = -0xffff;
$adjustments[ID3_Frame_RVAD::left] = 0xffff;
$adjustments[ID3_Frame_RVAD::peakRight] = 0xffff;
$adjustments[ID3_Frame_RVAD::peakLeft] = 0xfff;
$adjustments[ID3_Frame_RVAD::rightBack] = -0xff;
$adjustments[ID3_Frame_RVAD::leftBack] = 0xff;
$adjustments[ID3_Frame_RVAD::peakRightBack] = 0xff;
$adjustments[ID3_Frame_RVAD::peakLeftBack] = 0xf;
$adjustments[ID3_Frame_RVAD::center] = 0xf;
$adjustments[ID3_Frame_RVAD::peakCenter] = 0x7;
$adjustments[ID3_Frame_RVAD::bass] = 0x0;
$adjustments[ID3_Frame_RVAD::peakBass] = 0x0;
$adjustments[Zend_Media_Id3_Frame_RVAD::right] = -0xffff;
$adjustments[Zend_Media_Id3_Frame_RVAD::left] = 0xffff;
$adjustments[Zend_Media_Id3_Frame_RVAD::peakRight] = 0xffff;
$adjustments[Zend_Media_Id3_Frame_RVAD::peakLeft] = 0xfff;
$adjustments[Zend_Media_Id3_Frame_RVAD::rightBack] = -0xff;
$adjustments[Zend_Media_Id3_Frame_RVAD::leftBack] = 0xff;
$adjustments[Zend_Media_Id3_Frame_RVAD::peakRightBack] = 0xff;
$adjustments[Zend_Media_Id3_Frame_RVAD::peakLeftBack] = 0xf;
$adjustments[Zend_Media_Id3_Frame_RVAD::center] = 0xf;
$adjustments[Zend_Media_Id3_Frame_RVAD::peakCenter] = 0x7;
$adjustments[Zend_Media_Id3_Frame_RVAD::bass] = 0x0;
$adjustments[Zend_Media_Id3_Frame_RVAD::peakBass] = 0x0;
if ($action == self::INITIALIZE)
$frame->setAdjustments($adjustments);
@@ -935,9 +937,9 @@ final class TestID3Frame extends PHPUnit_Framework_TestCase
/**
* The first RVRB frame test.
*
* @param ID3_Frame_RVRB $frame The frame to test.
* @param Zend_Media_Id3_Frame_RVRB $frame The frame to test.
* @param boolean $action The requested action.
* @param integer $encoding The {@link ID3_Encoding text encoding} for strings
* @param integer $encoding The {@link Zend_Media_Id3_Encoding text encoding} for strings
* in this frame.
* @param string $language The language code.
* @param integer $timing The timing format.
@@ -984,9 +986,9 @@ final class TestID3Frame extends PHPUnit_Framework_TestCase
/**
* The first SEEK frame test.
*
* @param ID3_Frame_SEEK $frame The frame to test.
* @param Zend_Media_Id3_Frame_SEEK $frame The frame to test.
* @param boolean $action The requested action.
* @param integer $encoding The {@link ID3_Encoding text encoding} for strings
* @param integer $encoding The {@link Zend_Media_Id3_Encoding text encoding} for strings
* in this frame.
* @param string $language The language code.
* @param integer $timing The timing format.
@@ -1005,9 +1007,9 @@ final class TestID3Frame extends PHPUnit_Framework_TestCase
/**
* The first SIGN frame test.
*
* @param ID3_Frame_SIGN $frame The frame to test.
* @param Zend_Media_Id3_Frame_SIGN $frame The frame to test.
* @param boolean $action The requested action.
* @param integer $encoding The {@link ID3_Encoding text encoding} for strings
* @param integer $encoding The {@link Zend_Media_Id3_Encoding text encoding} for strings
* in this frame.
* @param string $language The language code.
* @param integer $timing The timing format.
@@ -1030,9 +1032,9 @@ final class TestID3Frame extends PHPUnit_Framework_TestCase
/**
* The first SYLT frame test.
*
* @param ID3_Frame_SYLT $frame The frame to test.
* @param Zend_Media_Id3_Frame_SYLT $frame The frame to test.
* @param boolean $action The requested action.
* @param integer $encoding The {@link ID3_Encoding text encoding} for strings
* @param integer $encoding The {@link Zend_Media_Id3_Encoding text encoding} for strings
* in this frame.
* @param string $language The language code.
* @param integer $timing The timing format.
@@ -1066,9 +1068,9 @@ final class TestID3Frame extends PHPUnit_Framework_TestCase
/**
* The first SYTC frame test.
*
* @param ID3_Frame_SYTC $frame The frame to test.
* @param Zend_Media_Id3_Frame_SYTC $frame The frame to test.
* @param boolean $action The requested action.
* @param integer $encoding The {@link ID3_Encoding text encoding} for strings
* @param integer $encoding The {@link Zend_Media_Id3_Encoding text encoding} for strings
* in this frame.
* @param string $language The language code.
* @param integer $timing The timing format.
@@ -1076,8 +1078,8 @@ final class TestID3Frame extends PHPUnit_Framework_TestCase
private function frameSYTC0
(&$frame, $action, $encoding, $language, $timing)
{
$events[0] = ID3_Frame_SYTC::BEAT_FREE;
$events[0xFFFF] = ID3_Frame_SYTC::SINGLE_BEAT;
$events[0] = Zend_Media_Id3_Frame_SYTC::BEAT_FREE;
$events[0xFFFF] = Zend_Media_Id3_Frame_SYTC::SINGLE_BEAT;
$events[0xFFFFF] = 0xFF;
$events[0xFFFFFF] = 0xFF + 1;
$events[0xFFFFFFFF] = 0xFF + 0xFF;
@@ -1091,9 +1093,9 @@ final class TestID3Frame extends PHPUnit_Framework_TestCase
/**
* The first TXXX frame test.
*
* @param ID3_Frame_TXXX $frame The frame to test.
* @param Zend_Media_Id3_Frame_TXXX $frame The frame to test.
* @param boolean $action The requested action.
* @param integer $encoding The {@link ID3_Encoding text encoding} for strings
* @param integer $encoding The {@link Zend_Media_Id3_Encoding text encoding} for strings
* in this frame.
* @param string $language The language code.
* @param integer $timing The timing format.
@@ -1121,9 +1123,9 @@ final class TestID3Frame extends PHPUnit_Framework_TestCase
/**
* The first USER frame test.
*
* @param ID3_Frame_USER $frame The frame to test.
* @param Zend_Media_Id3_Frame_USER $frame The frame to test.
* @param boolean $action The requested action.
* @param integer $encoding The {@link ID3_Encoding text encoding} for strings
* @param integer $encoding The {@link Zend_Media_Id3_Encoding text encoding} for strings
* in this frame.
* @param string $language The language code.
* @param integer $timing The timing format.
@@ -1146,9 +1148,9 @@ final class TestID3Frame extends PHPUnit_Framework_TestCase
/**
* The first USLT frame test.
*
* @param ID3_Frame_USLT $frame The frame to test.
* @param Zend_Media_Id3_Frame_USLT $frame The frame to test.
* @param boolean $action The requested action.
* @param integer $encoding The {@link ID3_Encoding text encoding} for strings
* @param integer $encoding The {@link Zend_Media_Id3_Encoding text encoding} for strings
* in this frame.
* @param string $language The language code.
* @param integer $timing The timing format.
@@ -1176,9 +1178,9 @@ final class TestID3Frame extends PHPUnit_Framework_TestCase
/**
* The first WXXX frame test.
*
* @param ID3_Frame_WXXX $frame The frame to test.
* @param Zend_Media_Id3_Frame_WXXX $frame The frame to test.
* @param boolean $action The requested action.
* @param integer $encoding The {@link ID3_Encoding text encoding} for strings
* @param integer $encoding The {@link Zend_Media_Id3_Encoding text encoding} for strings
* in this frame.
* @param string $language The language code.
* @param integer $timing The timing format.
@@ -1211,18 +1213,18 @@ final class TestID3Frame extends PHPUnit_Framework_TestCase
private static function convert($text, $encoding)
{
if ($encoding === null)
$encoding = ID3_Encoding::UTF8;
$encoding = Zend_Media_Id3_Encoding::UTF8;
switch ($encoding) {
case ID3_Encoding::ISO88591:
return iconv("utf-8", "iso-8859-1", $text);
case ID3_Encoding::UTF16:
return iconv("utf-8", "utf-16", $text);
case ID3_Encoding::UTF16LE:
return iconv("utf-8", "utf-16le", $text);
case ID3_Encoding::UTF16BE:
return iconv("utf-8", "utf-16be", $text);
default: // ID3_Encoding::UTF8
case Zend_Media_Id3_Encoding::ISO88591:
return iconv('utf-8', 'iso-8859-1', $text);
case Zend_Media_Id3_Encoding::UTF16:
return iconv('utf-8', 'utf-16', $text);
case Zend_Media_Id3_Encoding::UTF16LE:
return iconv('utf-8', 'utf-16le', $text);
case Zend_Media_Id3_Encoding::UTF16BE:
return iconv('utf-8', 'utf-16be', $text);
default: // Zend_Media_Id3_Encoding::UTF8
return $text;
}
}

View File

@@ -36,159 +36,159 @@
*/
/**#@+ @ignore */
require_once("PHPUnit/Framework.php");
require_once("ID3v1.php");
require_once 'PHPUnit/Framework.php';
require_once 'Zend/Media/Id3v1.php';
/**#@-*/
/**
* Unit test case for ID3v1 class.
* Unit test case for Id3v1 class.
*
* @package php-reader
* @subpackage Tests
* @author Sven Vollbehr <svollbehr@gmail.com>
* @copyright Copyright (c) 2008 The PHP Reader Project Workgroup
* @license http://code.google.com/p/php-reader/wiki/License New BSD License
* @version $Rev$
* @version $Id$
*/
final class TestID3v1 extends PHPUnit_Framework_TestCase
final class TestId3v1 extends PHPUnit_Framework_TestCase
{
function testTagCreate()
{
$id3 = new ID3v1();
$id3->title = "Title 1";
$this->assertEquals("Title 1", $id3->title);
$id3 = new Zend_Media_Id3v1();
$id3->artist = "Artist 1";
$this->assertEquals("Artist 1", $id3->artist);
$id3->title = 'Title 1';
$this->assertEquals('Title 1', $id3->title);
$id3->album = "Album 1";
$this->assertEquals("Album 1", $id3->album);
$id3->year = "2008";
$this->assertEquals("2008", $id3->year);
$id3->artist = 'Artist 1';
$this->assertEquals('Artist 1', $id3->artist);
$id3->album = 'Album 1';
$this->assertEquals('Album 1', $id3->album);
$id3->year = '2008';
$this->assertEquals('2008', $id3->year);
$id3->comment = 'Comment 1';
$this->assertEquals('Comment 1', $id3->comment);
$id3->comment = "Comment 1";
$this->assertEquals("Comment 1", $id3->comment);
$id3->track = 30;
$this->assertEquals(30, $id3->track);
$id3->genre = array_search("Classical", ID3v1::$genres);
$this->assertEquals("Classical", $id3->genre);
$id3->write("id3v1.tag");
$id3->genre = array_search('Classical', Zend_Media_Id3v1::$genres);
$this->assertEquals('Classical', $id3->genre);
$id3->write('id3v1.tag');
}
function testTagReadAfterCreate()
{
$id3 = new ID3v1("id3v1.tag");
$this->assertEquals("Title 1", $id3->title);
$this->assertEquals("Artist 1", $id3->artist);
$this->assertEquals("Album 1", $id3->album);
$this->assertEquals("2008", $id3->year);
$this->assertEquals("Comment 1", $id3->comment);
$id3 = new Zend_Media_Id3v1('id3v1.tag');
$this->assertEquals('Title 1', $id3->title);
$this->assertEquals('Artist 1', $id3->artist);
$this->assertEquals('Album 1', $id3->album);
$this->assertEquals('2008', $id3->year);
$this->assertEquals('Comment 1', $id3->comment);
$this->assertEquals(30, $id3->track);
$this->assertEquals("Classical", $id3->genre);
$this->assertEquals('Classical', $id3->genre);
}
function testTagChange()
{
$id3 = new ID3v1("id3v1.tag");
$id3->title = "Title 2";
$this->assertEquals("Title 2", $id3->title);
$id3 = new Zend_Media_Id3v1('id3v1.tag');
$id3->artist = "Artist 2";
$this->assertEquals("Artist 2", $id3->artist);
$id3->title = 'Title 2';
$this->assertEquals('Title 2', $id3->title);
$id3->album = "Album 2";
$this->assertEquals("Album 2", $id3->album);
$id3->year = "2045";
$this->assertEquals("2045", $id3->year);
$id3->artist = 'Artist 2';
$this->assertEquals('Artist 2', $id3->artist);
$id3->album = 'Album 2';
$this->assertEquals('Album 2', $id3->album);
$id3->year = '2045';
$this->assertEquals('2045', $id3->year);
$id3->comment = 'Comment 2';
$this->assertEquals('Comment 2', $id3->comment);
$id3->comment = "Comment 2";
$this->assertEquals("Comment 2", $id3->comment);
$id3->track = 10;
$this->assertEquals(10, $id3->track);
$id3->genre = array_search("Trance", ID3v1::$genres);
$this->assertEquals("Trance", $id3->genre);
$id3->genre = array_search('Trance', Zend_Media_Id3v1::$genres);
$this->assertEquals('Trance', $id3->genre);
$id3->write();
}
function testTagReadAfterChange()
{
$id3 = new ID3v1("id3v1.tag");
$this->assertEquals("Title 2", $id3->title);
$this->assertEquals("Artist 2", $id3->artist);
$this->assertEquals("Album 2", $id3->album);
$this->assertEquals("2045", $id3->year);
$this->assertEquals("Comment 2", $id3->comment);
$id3 = new Zend_Media_Id3v1('id3v1.tag');
$this->assertEquals('Title 2', $id3->title);
$this->assertEquals('Artist 2', $id3->artist);
$this->assertEquals('Album 2', $id3->album);
$this->assertEquals('2045', $id3->year);
$this->assertEquals('Comment 2', $id3->comment);
$this->assertEquals(10, $id3->track);
$this->assertEquals("Trance", $id3->genre);
$this->assertEquals('Trance', $id3->genre);
}
function testTagReplace()
{
$id3 = new ID3v1();
$id3->title = "Title 3";
$this->assertEquals("Title 3", $id3->title);
$this->assertEquals("Unknown", $id3->genre);
$id3->write("id3v1.tag");
$id3 = new Zend_Media_Id3v1();
$id3->title = 'Title 3';
$this->assertEquals('Title 3', $id3->title);
$this->assertEquals('Unknown', $id3->genre);
$id3->write('id3v1.tag');
}
function testTagReadAfterReplace()
{
$id3 = new ID3v1("id3v1.tag");
$this->assertEquals("Title 3", $id3->title);
$this->assertEquals("", $id3->artist);
$this->assertEquals("", $id3->album);
$this->assertEquals("", $id3->year);
$this->assertEquals("", $id3->comment);
$this->assertEquals("", $id3->track);
$this->assertEquals("Unknown", $id3->genre);
$id3 = new Zend_Media_Id3v1('id3v1.tag');
$this->assertEquals('Title 3', $id3->title);
$this->assertEquals('', $id3->artist);
$this->assertEquals('', $id3->album);
$this->assertEquals('', $id3->year);
$this->assertEquals('', $id3->comment);
$this->assertEquals('', $id3->track);
$this->assertEquals('Unknown', $id3->genre);
}
function testTagCreateVersion10()
{
$id3 = new ID3v1();
$id3->title = "Title 4";
$this->assertEquals("Title 4", $id3->title);
$id3 = new Zend_Media_Id3v1();
$id3->artist = "Artist 4";
$this->assertEquals("Artist 4", $id3->artist);
$id3->title = 'Title 4';
$this->assertEquals('Title 4', $id3->title);
$id3->album = "Album 4";
$this->assertEquals("Album 4", $id3->album);
$id3->year = "2020";
$this->assertEquals("2020", $id3->year);
$id3->artist = 'Artist 4';
$this->assertEquals('Artist 4', $id3->artist);
$id3->comment = "A comment field with 30 chars.";
$this->assertEquals("A comment field with 30 chars.", $id3->comment);
$id3->genre = array_search("Classical", ID3v1::$genres);
$this->assertEquals("Classical", $id3->genre);
$id3->write("id3v1.tag");
$id3->album = 'Album 4';
$this->assertEquals('Album 4', $id3->album);
$id3->year = '2020';
$this->assertEquals('2020', $id3->year);
$id3->comment = 'A comment field with 30 chars.';
$this->assertEquals('A comment field with 30 chars.', $id3->comment);
$id3->genre = array_search('Classical', Zend_Media_Id3v1::$genres);
$this->assertEquals('Classical', $id3->genre);
$id3->write('id3v1.tag');
}
function testTagReadAfterCreateVersion10()
{
$id3 = new ID3v1("id3v1.tag");
$this->assertEquals("Title 4", $id3->title);
$this->assertEquals("Artist 4", $id3->artist);
$this->assertEquals("Album 4", $id3->album);
$this->assertEquals("2020", $id3->year);
$this->assertEquals("A comment field with 30 chars.", $id3->comment);
$this->assertEquals("", $id3->track);
$this->assertEquals("Classical", $id3->genre);
$id3 = new Zend_Media_Id3v1('id3v1.tag');
$this->assertEquals('Title 4', $id3->title);
$this->assertEquals('Artist 4', $id3->artist);
$this->assertEquals('Album 4', $id3->album);
$this->assertEquals('2020', $id3->year);
$this->assertEquals('A comment field with 30 chars.', $id3->comment);
$this->assertEquals('', $id3->track);
$this->assertEquals('Classical', $id3->genre);
}
}

View File

@@ -36,103 +36,106 @@
*/
/**#@+ @ignore */
require_once("PHPUnit/Framework.php");
require_once("ID3v2.php");
require_once 'PHPUnit/Framework.php';
require_once 'Zend/Media/Id3v2.php';
/**#@-*/
/**
* Unit test case for ID3v2 class.
* Unit test case for Zend_Media_Id3v2 class.
*
* @package php-reader
* @subpackage Tests
* @author Sven Vollbehr <svollbehr@gmail.com>
* @copyright Copyright (c) 2008 The PHP Reader Project Workgroup
* @license http://code.google.com/p/php-reader/wiki/License New BSD License
* @version $Rev$
* @version $Id$
*/
final class TestID3v2 extends PHPUnit_Framework_TestCase
{
function testTagCreate()
{
$id3 = new ID3v2();
$id3->tit2->text = "Title 1";
$this->assertEquals("Title 1", $id3->tit2->text);
$id3->tope->text = "Artist 1";
$this->assertEquals("Artist 1", $id3->tope->text);
$id3->talb->text = "Album 1";
$this->assertEquals("Album 1", $id3->talb->text);
$id3->tdrc->text = "2008";
$this->assertEquals("2008", $id3->tdrc->text);
$id3->comm->text = "Comment 1";
$this->assertEquals("Comment 1", $id3->comm->text);
$id3->trck->text = "11/13";
$this->assertEquals("11/13", $id3->trck->text);
$id3->tcon->text = "Classical";
$this->assertEquals("Classical", $id3->tcon->text);
$id3->write("id3v2.tag");
$id3 = new Zend_Media_Id3v2();
$id3->tit2->text = 'Title 1';
$this->assertEquals('Title 1', $id3->tit2->text);
$id3->tope->text = 'Artist 1';
$this->assertEquals('Artist 1', $id3->tope->text);
$id3->talb->text = 'Album 1';
$this->assertEquals('Album 1', $id3->talb->text);
$id3->tdrc->text = '2008';
$this->assertEquals('2008', $id3->tdrc->text);
$id3->comm->text = 'Comment 1';
$this->assertEquals('Comment 1', $id3->comm->text);
$id3->trck->text = '11/13';
$this->assertEquals('11/13', $id3->trck->text);
$id3->tcon->text = 'Classical';
$this->assertEquals('Classical', $id3->tcon->text);
$id3->write('id3v2.tag');
}
function testTagReadAfterCreate()
{
$id3 = new ID3v2("id3v2.tag");
$this->assertEquals("Title 1", $id3->tit2->text);
$this->assertEquals("Artist 1", $id3->tope->text);
$this->assertEquals("Album 1", $id3->talb->text);
$this->assertEquals("2008", $id3->tdrc->text);
$this->assertEquals("Comment 1", $id3->comm->text);
$this->assertEquals("11/13", $id3->trck->text);
$this->assertEquals("Classical", $id3->tcon->text);
$id3 = new Zend_Media_Id3v2('id3v2.tag');
$this->assertEquals('Title 1', $id3->tit2->text);
$this->assertEquals('Artist 1', $id3->tope->text);
$this->assertEquals('Album 1', $id3->talb->text);
$this->assertEquals('2008', $id3->tdrc->text);
$this->assertEquals('Comment 1', $id3->comm->text);
$this->assertEquals('11/13', $id3->trck->text);
$this->assertEquals('Classical', $id3->tcon->text);
}
function testTagChange()
{
$id3 = new ID3v2("id3v2.tag");
$id3->tit2->text = "Title 2";
$this->assertEquals("Title 2", $id3->tit2->text);
$id3->tope->text = "Artist 2";
$this->assertEquals("Artist 2", $id3->tope->text);
$id3->talb->text = "Album 2";
$this->assertEquals("Album 2", $id3->talb->text);
$id3->tdrc->text = "2020";
$this->assertEquals("2020", $id3->tdrc->text);
$id3->comm->text = "Comment 2";
$this->assertEquals("Comment 2", $id3->comm->text);
$id3->trck->text = "13/13";
$this->assertEquals("13/13", $id3->trck->text);
$id3->tcon->text = "Trance";
$this->assertEquals("Trance", $id3->tcon->text);
$id3->write();
$id3 = new Zend_Media_Id3v2('id3v2.tag');
$id3->tit2->text = 'Title 2';
$this->assertEquals('Title 2', $id3->tit2->text);
$id3->tope->text = 'Artist 2';
$this->assertEquals('Artist 2', $id3->tope->text);
$id3->talb->text = 'Album 2';
$this->assertEquals('Album 2', $id3->talb->text);
$id3->tdrc->text = '2020';
$this->assertEquals('2020', $id3->tdrc->text);
$id3->comm->text = 'Comment 2';
$this->assertEquals('Comment 2', $id3->comm->text);
$id3->trck->text = '13/13';
$this->assertEquals('13/13', $id3->trck->text);
$id3->tcon->text = 'Trance';
$this->assertEquals('Trance', $id3->tcon->text);
$id3->write(null);
}
function testTagReadAfterChange()
{
$id3 = new ID3v2("id3v2.tag");
$this->assertEquals("Title 2", $id3->tit2->text);
$this->assertEquals("Artist 2", $id3->tope->text);
$this->assertEquals("Album 2", $id3->talb->text);
$this->assertEquals("2020", $id3->tdrc->text);
$this->assertEquals("Comment 2", $id3->comm->text);
$this->assertEquals("13/13", $id3->trck->text);
$this->assertEquals("Trance", $id3->tcon->text);
$id3 = new Zend_Media_Id3v2('id3v2.tag');
$this->assertEquals('Title 2', $id3->tit2->text);
$this->assertEquals('Artist 2', $id3->tope->text);
$this->assertEquals('Album 2', $id3->talb->text);
$this->assertEquals('2020', $id3->tdrc->text);
$this->assertEquals('Comment 2', $id3->comm->text);
$this->assertEquals('13/13', $id3->trck->text);
$this->assertEquals('Trance', $id3->tcon->text);
}
function testUnsynchronisation()
{
$id3 = new ID3v2("id3v2.tag");
$id3 = new Zend_Media_Id3v2('id3v2.tag');
$id3->tit2->text = "\xff\xf0";
$id3->tcon->text = "\xff\xe0\xf0";
$id3->write();
$id3->write(null);
$buffer = new Zend_Io_StringWriter();
$id3->tit2->write($buffer);
$this->assertEquals
("TIT2\0\0\0\x08\0\x03\0\0\0\x03\x03\xff\x00\xf0", "" . $id3->tit2);
$id3 = new ID3v2("id3v2.tag");
("TIT2\0\0\0\x08\0\x03\0\0\0\x03\x03\xff\x00\xf0", $buffer->toString());
$id3 = new Zend_Media_Id3v2('id3v2.tag');
$this->assertEquals("\xff\xf0", $id3->tit2->text);
$this->assertEquals("\xff\xe0\xf0", $id3->tcon->text);
}

View File

@@ -1,188 +0,0 @@
<?php
/**
* PHP Reader Library
*
* Copyright (c) 2008-2009 The PHP Reader Project Workgroup. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* - Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* - Neither the name of the project workgroup nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* @package php-reader
* @subpackage Tests
* @copyright Copyright (c) 2008-2009 The PHP Reader Project Workgroup
* @license http://code.google.com/p/php-reader/wiki/License New BSD License
* @version $Id$
*/
/**#@+ @ignore */
require_once("PHPUnit/Framework.php");
require_once("Transform.php");
/**#@-*/
/**
* Unit test case for Transform class.
*
* @package php-reader
* @subpackage Tests
* @author Sven Vollbehr <svollbehr@gmail.com>
* @author Ryan Butterfield <buttza@gmail.com>
* @copyright Copyright (c) 2008-2009 The PHP Reader Project Workgroup
* @license http://code.google.com/p/php-reader/wiki/License New BSD License
* @version $Rev$
*/
final class TestTransform extends PHPUnit_Framework_TestCase
{
function testInt64LE()
{
$this->assertEquals
(0x7fffffffffffffff, Transform::fromInt64BE
(Transform::toInt64BE(0x7fffffffffffffff)));
}
function testInt64BE()
{
$this->assertEquals
(0x7fffffffffffffff, Transform::fromInt64BE
(Transform::toInt64BE(0x7fffffffffffffff)));
}
function testInt32()
{
$this->assertEquals
(0x7fffffff, Transform::fromInt32(Transform::toInt32(0x7fffffff)));
$this->assertEquals
(-0x7fffffff, Transform::fromInt32(Transform::toInt32(-0x7fffffff)));
$this->assertEquals(-1, Transform::fromInt32(Transform::toInt32(-1)));
}
function testInt32LE()
{
$this->assertEquals(1, Transform::fromInt32LE("\x01\x00\x00\x00"));
$this->assertEquals
(0x7fffffff, Transform::fromInt32LE(Transform::toInt32LE(0x7fffffff)));
$this->assertEquals
(-0x7fffffff, Transform::fromInt32LE(Transform::toInt32LE(-0x7fffffff)));
$this->assertEquals(-1, Transform::fromInt32LE(Transform::toInt32LE(-1)));
}
function testInt32BE()
{
$this->assertEquals(1, Transform::fromInt32BE("\x00\x00\x00\x01"));
$this->assertEquals
(0x7fffffff, Transform::fromInt32BE(Transform::toInt32BE(0x7fffffff)));
$this->assertEquals
(-0x7fffffff, Transform::fromInt32BE(Transform::toInt32BE(-0x7fffffff)));
}
function testUInt32LE()
{
$this->assertEquals
("78563412", Transform::fromHHex(Transform::toUInt32LE(0x12345678)));
$this->assertEquals
(0xffffffff, Transform::fromUInt32LE(Transform::toUInt32LE(0xffffffff)));
}
function testUInt32BE()
{
$this->assertEquals
("12345678", Transform::fromHHex(Transform::toUInt32BE(0x12345678)));
$this->assertEquals
(0xffffffff, Transform::fromUInt32BE(Transform::toUInt32BE(0xffffffff)));
}
function testInt16()
{
$this->assertEquals
(0x7fff, Transform::fromInt16(Transform::toInt16(0x7fff)));
$this->assertEquals(-1, Transform::fromInt16(Transform::toInt16(-1)));
}
function testInt16LE()
{
$this->assertEquals(1, Transform::fromInt16LE("\x01\x00"));
$this->assertEquals
(0x7fff, Transform::fromInt16LE(Transform::toInt16LE(0x7fff)));
$this->assertEquals(-1, Transform::fromInt16LE(Transform::toInt16LE(-1)));
}
function testInt16BE()
{
$this->assertEquals(1, Transform::fromInt16BE("\x00\x01"));
$this->assertEquals
(0x7fff, Transform::fromInt16BE(Transform::toInt16BE(0x7fff)));
$this->assertEquals(-1, Transform::fromInt16BE(Transform::toInt16BE(-1)));
}
function testUInt16LE()
{
$this->assertEquals
("fffe", Transform::fromHHex(Transform::toUInt16LE(0xfeff)));
$this->assertEquals
(0xffff, Transform::fromUInt16LE(Transform::toUInt16LE(0xffff)));
}
function testUInt16BE()
{
$this->assertEquals
("feff", Transform::fromHHex(Transform::toUInt16BE(0xfeff)));
$this->assertEquals
(0xffff, Transform::fromUInt16BE(Transform::toUInt16BE(0xffff)));
}
function testInt8()
{
$this->assertEquals(0x7f, Transform::fromInt8(Transform::toInt8(0x7f)));
}
function testString16()
{
$this->assertEquals("00e4", Transform::fromHHex
(Transform::fromString16(Transform::toString16("\x00\xe4"))));
$this->assertEquals
("\xff\xfe\0T\0h\0i\0s\0 \0i\0s\0 \0a\0 \0t\0e\0s\0t\0.",
Transform::fromString16(Transform::toString16
("\xff\xfe\0T\0h\0i\0s\0 \0i\0s\0 \0a\0 \0t\0e\0s\0t\0.")));
}
function testHHex()
{
$this->assertEquals("6c34", bin2hex(Transform::toHHex("6c34")));
$this->assertEquals("6c34", Transform::fromHHex(Transform::toHHex("6c34")));
}
function testLHex()
{
$this->assertEquals("c643", bin2hex(Transform::toLHex("6c34")));
$this->assertEquals("6c34", Transform::fromLHex(Transform::toLHex("6c34")));
}
function testGUID()
{
$this->assertEquals
("75b22630-668e-11cf-a6d9-00aa0062ce6c",
Transform::fromGUID(Transform::toGUID
("75b22630-668e-11cf-a6d9-00aa0062ce6c")));
}
}