@ -44,6 +44,79 @@ function islandora_hex2int($hex) {
}
}
}
}
/**
* A result from a datastream validator; $type defines TRUE/FALSE as pass/fail.
*/
class DatastreamValidatorResult {
/**
* The message for this result.
*
* @var string
*/
protected $message;
/**
* The caller for this result.
*
* @var array
*/
protected $caller;
/**
* The type of result this is - TRUE for pass, FALSE for fail.
*
* @var bool
*/
protected $type;
/**
* Constructs a DatastreamValidatorResult.
*
* @param bool $type
* Whether this result should indicate a pass (TRUE) or fail (FALSE).
* @param string $message
* The message that will be used by this result.
* @param array $caller
* The caller for this result.
*/
public function __construct($type, $message, array $caller) {
$this->message = $message;
$this->caller = $caller;
$this->type = $type;
}
/**
* Get the message for this result.
*
* @return string
* The message for this result.
*/
public function getMessage() {
return $this->message;
}
/**
* Get the caller for this result.
*
* @return string
* The caller for this result.
*/
public function getCaller() {
return $this->caller;
}
/**
* Get the type of result.
*
* @return bool
* The type of pass (TRUE for pass, FALSE for fail).
*/
public function getType() {
return $this->type;
}
}
/**
/**
* Abstraction for datastream validators.
* Abstraction for datastream validators.
*
*
@ -66,13 +139,6 @@ function islandora_hex2int($hex) {
*/
*/
abstract class DatastreamValidator {
abstract class DatastreamValidator {
/**
* This class is skipped when looking for the source of an assertion.
*
* @see DrupalWebTestCase::skipClasses
*/
protected $skipClasses = array(__CLASS__ => TRUE);
/**
/**
* The IslandoraFedoraObject containing the datastream to test.
* The IslandoraFedoraObject containing the datastream to test.
*
*
@ -95,24 +161,13 @@ abstract class DatastreamValidator {
public $datastreamContent;
public $datastreamContent;
/**
/**
* An associative array of messages returned from passed tests, and callers.
* An array of DatastreamValidatorResults.
*
* This should only be added to using $this->addPass(), so that the caller can
* be appropriately determined.
*
* @var array
*/
public $passes = array();
/**
* An associative array of messages returned from failed tests, and callers.
*
*
* This should only be added to using $this->addFail(), so that the caller can
* These should be generated using $this->addResult.
* be appropriately determined.
*
*
* @var array
* @var DatastreamValidatorResult[]
*/
*/
public $fail s = array();
public $results = array();
/**
/**
* An array of additional required parameters.
* An array of additional required parameters.
@ -157,49 +212,26 @@ abstract class DatastreamValidator {
}
}
/**
/**
* Returns an array of pass message s.
* Returns an array of DatastreamValidatorResult s.
*
*
* @return string []
* @return DatastreamValidatorResult []
* The pass message s.
* The result s.
*/
*/
public function getPasse s() {
public function getResult s() {
return $this->passe s;
return $this->result s;
}
}
/**
/**
* Returns an array of fail messages.
* Adds a result to $this->results.
*
* @return string[]
* The fail messages.
*/
public function getFails() {
return $this->fails;
}
/**
* Adds a pass to $this->pass.
*
* Passes are an associative array of messages and callers. Callers should be
* obtained using $this->getAssertionCall().
*
*
* @param bool $type
* The type of result (TRUE for pass, FALSE for fail).
* @param string $message
* @param string $message
* The message to use.
* The message to put in the result.
*/
*/
public function addPass($message) {
public function addResult($type, $message) {
$this->passes[$message] = $this->getAssertionCall();
$result = new DatastreamValidatorResult($type, $message, $this->getAssertionCall());
}
$this->results[] = $result;
/**
* Adds a fail to $this->fail.
*
* Fails are an associative array of messages and callers. Callers should be
* obtained using $this->getAssertionCall().
*
* @param string $message
* The message to use.
*/
public function addFail($message) {
$this->fails[$message] = $this->getAssertionCall();
}
}
/**
/**
@ -239,12 +271,11 @@ class ImageDatastreamValidator extends DatastreamValidator {
* Asserts the validity of an image using PHPGD.
* Asserts the validity of an image using PHPGD.
*/
*/
protected function assertImageGeneration() {
protected function assertImageGeneration() {
if (imagecreatefromstring($this->datastreamContent) !== FALSE) {
$assertion = imagecreatefromstring($this->datastreamContent) !== FALSE;
$this->addPass("Image datastream {$this->datastream} is valid.");
$pass = "Image datastream {$this->datastream} is valid.";
}
$fail = "Image datastream {$this->datastream} is either invalid or corrupt.";
else {
$message = $assertion ? $pass : $fail;
$this->addFail("Image datastream {$this->datastream} is either invalid or corrupt.");
$this->addResult($assertion, $message);
}
}
}
}
}
@ -264,17 +295,17 @@ class TIFFDatastreamValidator extends DatastreamValidator {
// byte-order" (i.e. little-endian) by starting with the characters "II"
// byte-order" (i.e. little-endian) by starting with the characters "II"
// (repeated so that byte order does not yet need to be significant).
// (repeated so that byte order does not yet need to be significant).
// The number that follows is '42' in little-endian hex, a number of
// The number that follows is '42' in little-endian hex, a number of
// 'deep philosophical significance' to the TIFF format creators.
// 'deep philosophical significance' to the TIFF format creators.'
$this->addPass( "{$this->datastream} datastream asserts that it is a valid Intel-byte-orderded TIF/TIFF file.");
$this->addResult(TRUE, "{$this->datastream} datastream asserts that it is a valid Intel-byte-orderded TIF/TIFF file.");
}
}
elseif ($datastream_header_hex == "4d4d002a") {
elseif ($datastream_header_hex == "4d4d002a") {
// In this case, the ingested TIFF is designated as using the "Motorola
// In this case, the ingested TIFF is designated as using the "Motorola
// byte-order" (i.e. big-endian) by starting with the characters "MM"
// byte-order" (i.e. big-endian) by starting with the characters "MM"
// instead. 42 follows once again, this time in big-endian hex.
// instead. 42 follows once again, this time in big-endian hex.
$this->addPass( "{$this->datastream} datastream asserts that it is a valid Motorola-byte-ordered TIF/TIFF file.");
$this->addResult(TRUE, "{$this->datastream} datastream asserts that it is a valid Motorola-byte-ordered TIF/TIFF file.");
}
}
else {
else {
$this->addFail( "{$this->datastream} datastream does not assert that it is a valid TIF/TIFF file.");
$this->addResult(FALSE, "{$this->datastream} datastream does not assert that it is a valid TIF/TIFF file.");
}
}
}
}
@ -302,12 +333,11 @@ class JP2DatastreamValidator extends DatastreamValidator {
* 0x6A502020. This header is in all .jp2s, and we check for it here.
* 0x6A502020. This header is in all .jp2s, and we check for it here.
*/
*/
protected function assertJP2Header() {
protected function assertJP2Header() {
if (substr(bin2hex($this->datastreamContent), 8, 8) == '6a502020') {
$assertion = substr(bin2hex($this->datastreamContent), 8, 8) == '6a502020';
$this->addPass("Datastream {$this->datastream} contains the appropriate JP2 header.");
$pass = "Datastream {$this->datastream} contains the appropriate JP2 header.";
}
$fail = "Datastream {$this->datastream} does not contain the appropriate JP2 header.";
else {
$message = $assertion ? $pass : $fail;
$this->addFail("Datastream {$this->datastream} does not contain the appropriate JP2 header.");
$this->addResult($assertion, $message);
}
}
}
/**
/**
@ -317,12 +347,11 @@ class JP2DatastreamValidator extends DatastreamValidator {
* checking for it here to see if the .jp2 encoder finished okay.
* checking for it here to see if the .jp2 encoder finished okay.
*/
*/
protected function assertJP2Marker() {
protected function assertJP2Marker() {
if (substr(bin2hex($this->datastreamContent), strlen(bin2hex($this->datastreamContent)) - 4, 4) == 'ffd9') {
$assertion = substr(bin2hex($this->datastreamContent), strlen(bin2hex($this->datastreamContent)) - 4, 4) == 'ffd9';
$this->addPass("Datastream {$this->datastream} contains the appropriate JP2 ending marker.");
$pass = "Datastream {$this->datastream} contains the appropriate JP2 ending marker.";
}
$fail = "Datastream {$this->datastream} does not contain the appropriate JP2 ending marker. If this is the only JP2 validator that failed, it is likely that derivative generation was interrupted.";
else {
$message = $assertion ? $pass : $fail;
$this->addFail("Datastream {$this->datastream} does not contain the appropriate JP2 ending marker. If this is the only JP2 validator that failed, it is likely that derivative generation was interrupted.");
$this->addResult($assertion, $message);
}
}
}
}
}
@ -335,13 +364,12 @@ class PDFDatastreamValidator extends DatastreamValidator {
* Validates the PDF signature.
* Validates the PDF signature.
*/
*/
protected function assertPDFSignature() {
protected function assertPDFSignature() {
if (substr($this->datastreamContent, 0, 5) == '%PDF-') {
$assertion = substr($this->datastreamContent, 0, 5) == '%PDF-';
$pdf_version = substr($this->datastreamContent, 5, 3);
$pdf_version = substr($this->datastreamContent, 5, 3);
$this->addPass("{$this->datastream} datastream asserts that it is a valid PDF file using PDF version {$pdf_version}");
$pass = "{$this->datastream} datastream asserts that it is a valid PDF file using PDF version {$pdf_version}";
}
$fail = "{$this->datastream} datastream binary header appears to be corrupt and missing a valid PDF signature.";
else {
$message = $assertion ? $pass : $fail;
$this->addFail("{$this->datastream} datastream binary header appears to be corrupt and missing a valid PDF signature.");
$this->addResult($assertion, $message);
}
}
}
/**
/**
@ -349,12 +377,11 @@ class PDFDatastreamValidator extends DatastreamValidator {
*/
*/
protected function assertPDFStreamCount() {
protected function assertPDFStreamCount() {
$pdf_stream_count = substr_count(bin2hex($this->datastreamContent), '0a73747265616d0a');
$pdf_stream_count = substr_count(bin2hex($this->datastreamContent), '0a73747265616d0a');
if ($pdf_stream_count !== 0) {
$assertion = $pdf_stream_count !== 0;
$this->addPass("{$this->datastream} datastream reports the existence of {$pdf_stream_count} PDF streams. Note that an extremely low number could still indicate corruption.");
$pass = "{$this->datastream} datastream reports the existence of {$pdf_stream_count} PDF streams. Note that an extremely low number could still indicate corruption.";
}
$fail = "{$this->datastream} datastream contains zero PDF streams, and is likely not a PDF file.";
else {
$message = $assertion ? $pass : $fail;
$this->addFail("{$this->datastream} datastream contains zero PDF streams, and is likely not a PDF file.");
$this->addResult($assertion, $message);
}
}
}
/**
/**
@ -364,12 +391,11 @@ class PDFDatastreamValidator extends DatastreamValidator {
* TRUE if it was present; FALSE otherwise.
* TRUE if it was present; FALSE otherwise.
*/
*/
protected function assertPDFClosingTag() {
protected function assertPDFClosingTag() {
if (strpos(bin2hex($this->datastreamContent), '0a2525454f460a')) {
$assertion = strpos(bin2hex($this->datastreamContent), '0a2525454f460a') == TRUE;
$this->addPass("{$this->datastream} datastream reports the existence of the closing 'EOF' tag required at the end of PDFs");
$pass = "{$this->datastream} datastream reports the existence of the closing 'EOF' tag required at the end of PDFs";
}
$fail = "{$this->datastream} datastream does not contain the closing 'EOF' tag. If this is the only PDF validation that failed, it is likely that derivative generation was interrupted.";
else {
$message = $assertion ? $pass : $fail;
$this->addFail("{$this->datastream} datastream does not contain the closing 'EOF' tag. If this is the only PDF validation that failed, it is likely that derivative generation was interrupted.");
$this->addResult($assertion, $message);
}
}
}
}
}
@ -387,13 +413,13 @@ class TextDatastreamValidator extends DatastreamValidator {
*/
*/
protected function assertTextStringCount() {
protected function assertTextStringCount() {
if (!isset($this->params[1])) {
if (!isset($this->params[1])) {
$this->addFail( "TextDatastreamValidator cannot be instantiated without two keys in the 'params' variable.");
$this->addResult(FALSE, "TextDatastreamValidator cannot be instantiated without two keys in the 'params' variable.");
return;
return;
}
}
$string_count = self::getTextStringCount();
$string_count = self::getTextStringCount();
$expected = $this->params[1];
$expected = $this->params[1];
$function = $string_count === $expected ? 'addPass' : 'addFail' ;
$assertion = $string_count === $expected ;
$this->$function( "{$this->datastream} datastream contains the word(s) '{$this->params[0]}' repeated {$string_count} time(s) (expected: {$expected}).");
$this->addResult($assertion, "{$this->datastream} datastream contains the word(s) '{$this->params[0]}' repeated {$string_count} time(s) (expected: {$expected}).");
}
}
/**
/**
@ -442,36 +468,33 @@ class WAVDatastreamValidator extends DatastreamValidator {
*/
*/
protected function assertWAVSignature() {
protected function assertWAVSignature() {
$signatures = str_split(substr($this->datastreamContent, 0, 24), 8);
$signatures = str_split(substr($this->datastreamContent, 0, 24), 8);
if ($signatures[0] = '52494646' & & $signatures[2] = '57415645') {
$assertion = $signatures[0] == '52494646' & & $signatures[2] == '57415645';
$this->addPass("Header of the {$this->datastream} datastream contains a valid file signature.");
$pass = "Header of the {$this->datastream} datastream contains a valid file signature.";
}
$fail = "Header of the {$this->datastream} datastream contains corrupt file signature.";
else {
$message = $assertion ? $pass : $fail;
$this->addFail("Header of the {$this->datastream} datastream contains corrupt file signature.");
$this->addResult($assertion, $message);
}
}
}
/**
/**
* Asserts that the chunksize in the header is correct.
* Asserts that the chunksize in the header is correct.
*/
*/
protected function assertWAVChunkSize() {
protected function assertWAVChunkSize() {
if (islandora_hex2int(substr($this->datastreamContent, 8, 8)) === 36 + self::getDataSubChunkSize()) {
$assertion = islandora_hex2int(substr($this->datastreamContent, 8, 8)) === 36 + self::getDataSubChunkSize();
$this->addPass("{$this->datastream} datastream chunksize in WAV header is correct");
$pass = "{$this->datastream} datastream chunksize in WAV header is correct";
}
$fail = "{$this->datastream} datastream chunksize in WAV header does not match actual chunksize.";
else {
$message = $assertion ? $pass : $fail;
$this->addFail("{$this->datastream} datastream chunksize in WAV header does not match actual chunksize.");
$this->addResult($assertion, $message);
}
}
}
/**
/**
* Asserts that the datastream contains a 'fmt' subchunk.
* Asserts that the datastream contains a 'fmt' subchunk.
*/
*/
protected function assertWAVFmtSubChunk() {
protected function assertWAVFmtSubChunk() {
if (substr($this->datastreamContent, 24, 8) === '666d7420') {
$assertion = substr($this->datastreamContent, 24, 8) === '666d7420';
$this->addPass("{$this->datastream} datastream contains a 'fmt' subchunk.");
$pass = "{$this->datastream} datastream contains a 'fmt' subchunk.";
}
$fail = "{$this->datastream} datastream is missing the required 'fmt' subchunk.";
else {
$message = $assertion ? $pass : $fail;
$this->addFail("{$this->datastream} datastream is missing the required 'fmt' subchunk.");
$this->addResult($assertion, $message);
}
}
}
/**
/**
@ -479,24 +502,22 @@ class WAVDatastreamValidator extends DatastreamValidator {
*/
*/
protected function assertWAVByteRate() {
protected function assertWAVByteRate() {
$wav_samplerate = islandora_hex2int(substr($this->datastreamContent, 48, 8));
$wav_samplerate = islandora_hex2int(substr($this->datastreamContent, 48, 8));
if (islandora_hex2int(substr($this->datastreamContent, 56, 8)) === $wav_samplerate * self::getNumChannels() * self::getBytesPerSample()) {
$assertion = islandora_hex2int(substr($this->datastreamContent, 56, 8)) === $wav_samplerate * self::getNumChannels() * self::getBytesPerSample();
$this->addPass("{$this->datastream} datastream byterate in the WAV header is correct.");
$pass = "{$this->datastream} datastream byterate in the WAV header is correct.";
}
$fail = "{$this->datastream} datastream byterate in the WAV header does not match actual calculated byterate.";
else {
$message = $assertion ? $pass : $fail;
$this->addFail("{$this->datastream} datastream byterate in the WAV header does not match actual calculated byterate.");
$this->addResult($assertion, $message);
}
}
}
/**
/**
* Asserts that the block alignment is correct.
* Asserts that the block alignment is correct.
*/
*/
protected function assertWAVBlockAlignment() {
protected function assertWAVBlockAlignment() {
if (islandora_hex2int(substr($this->datastreamContent, 64, 4)) === self::getNumChannels() * self::getBytesPerSample()) {
$assertion = islandora_hex2int(substr($this->datastreamContent, 64, 4)) === self::getNumChannels() * self::getBytesPerSample();
$this->addPass("{$this->datastream} datastream block alignment is set correctly.");
$pass = "{$this->datastream} datastream block alignment is set correctly.";
}
$fail = "{$this->datastream} datastream block alignment is off.";
else {
$message = $assertion ? $pass : $fail;
$this->addFail("{$this->datastream} datastream block alignment is off.");
$this->addResult($assertion, $message);
}
}
}
/**
/**
@ -506,18 +527,17 @@ class WAVDatastreamValidator extends DatastreamValidator {
*/
*/
protected function assertWAVDataSubChunk() {
protected function assertWAVDataSubChunk() {
if (substr($this->datastreamContent, 72, 8) !== '64617461') {
if (substr($this->datastreamContent, 72, 8) !== '64617461') {
$this->addFail( "{$this->datastream} datastream is missing the 'data' subchunk.");
$this->addResult(FALSE, "{$this->datastream} datastream is missing the 'data' subchunk.");
return;
return;
}
}
else {
else {
$this->addPass( "{$this->datastream} datastream contains 'data' subchunk.");
$this->addResult(TRUE, "{$this->datastream} datastream contains 'data' subchunk.");
$wav_numsamples = strlen(substr($this->datastreamContent, 88)) / self::getNumChannels() / self::getBytesPerSample() / 2;
$wav_numsamples = strlen(substr($this->datastreamContent, 88)) / self::getNumChannels() / self::getBytesPerSample() / 2;
if (self::getDataSubChunkSize() === $wav_numsamples * self::getNumChannels() * self::getBytesPerSample()) {
$assertion = self::getDataSubChunkSize() === $wav_numsamples * self::getNumChannels() * self::getBytesPerSample();
$this->addPass("{$this->datastream} datastream 'data' chunk is the correct size.");
$pass = "{$this->datastream} datastream 'data' chunk is the correct size.";
}
$fail = "{$this->datastream} datastream 'data' chunk is sized incorrectly.";
else {
$message = $assertion ? $pass : $fail;
$this->addFail("{$this->datastream} datastream 'data' chunk is sized incorrectly.");
$this->addResult($assertion, $message);
}
}
}
}
}
@ -578,11 +598,11 @@ class MP3DatastreamValidator extends DatastreamValidator {
// out of the way first before we go doing a bunch of potentially pointless
// out of the way first before we go doing a bunch of potentially pointless
// math. Check to see if the VBR flag (58696e67) isn't there.
// math. Check to see if the VBR flag (58696e67) isn't there.
if (strpos($this->datastreamContent, '58696e67') == FALSE & & substr($this->datastreamContent, 0, 4) == 'fffa') {
if (strpos($this->datastreamContent, '58696e67') == FALSE & & substr($this->datastreamContent, 0, 4) == 'fffa') {
$this->addPass( "{$this->datastream} datastream is encoded as a valid MPEG-1 Layer 3 file with CRC protection");
$this->addResult(TRUE, "{$this->datastream} datastream is encoded as a valid MPEG-1 Layer 3 file with CRC protection");
return;
return;
}
}
if (strpos($this->datastreamContent, '58696e67') == FALSE & & substr($this->datastreamContent, 0, 4) == 'fffb') {
if (strpos($this->datastreamContent, '58696e67') == FALSE & & substr($this->datastreamContent, 0, 4) == 'fffb') {
$this->addPass( "{$this->datastream} datastream is encoded as a valid unprotected MPEG-1 Layer 3 file");
$this->addResult(TRUE, "{$this->datastream} datastream is encoded as a valid unprotected MPEG-1 Layer 3 file");
return;
return;
}
}
@ -610,12 +630,11 @@ class MP3DatastreamValidator extends DatastreamValidator {
if (($mp3_flag_value + 4) % 4 > 1) {
if (($mp3_flag_value + 4) % 4 > 1) {
$mp3_field_bytes = hexdec(substr($mp3_vbrheader, $mp3_field_offset[0] + 16, 8));
$mp3_field_bytes = hexdec(substr($mp3_vbrheader, $mp3_field_offset[0] + 16, 8));
$mp3_size = strlen($this->datastreamContent) / 2;
$mp3_size = strlen($this->datastreamContent) / 2;
if ($mp3_size == $mp3_field_bytes) {
$assertion = $mp3_size == $mp3_field_bytes;
$this->addPass("{$this->datastream} datastream reported filesize of {$mp3_size} bytes matches size field value of {$mp3_field_bytes}");
$pass = "{$this->datastream} datastream reported filesize of {$mp3_size} bytes matches size field value of {$mp3_field_bytes}";
}
$fail = "{$this->datastream} datastream reported filesize of {$mp3_size} bytes does not match size field value of {$mp3_field_bytes}";
else {
$message = $assertion ? $pass : $fail;
$this->addFail("{$this->datastream} datastream reported filesize of {$mp3_size} bytes does not match size field value of {$mp3_field_bytes}");
$this->addResult($assertion, $message);
}
$mp3_field_offset[1] += 8;
$mp3_field_offset[1] += 8;
$mp3_field_offset[2] += 8;
$mp3_field_offset[2] += 8;
}
}
@ -628,18 +647,17 @@ class MP3DatastreamValidator extends DatastreamValidator {
// The fourth flag leads us to VBR quality data, which we can validate.
// The fourth flag leads us to VBR quality data, which we can validate.
if ($mp3_flag_value > 7) {
if ($mp3_flag_value > 7) {
$mp3_field_quality = hexdec(substr($mp3_vbrheader, $mp3_field_offset[2] + 16, 8));
$mp3_field_quality = hexdec(substr($mp3_vbrheader, $mp3_field_offset[2] + 16, 8));
if ($mp3_field_quality < = 100 & & $mp3_field_quality >= 0) {
$assertion = $mp3_field_quality < = 100 & & $mp3_field_quality >= 0;
$this->addPass("{$this->datastream} datastream reports valid VBR quality of {$mp3_field_quality} (expected: between 0-100)");
$pass = "{$this->datastream} datastream reports valid VBR quality of {$mp3_field_quality} (expected: between 0-100)";
}
$fail = "{$this->datastream} datastream reports invalid VBR quality of {$mp3_field_quality} (expected: between 0-100)";
else {
$message = $assertion ? $pass : $fail;
$this->addFail("{$this->datastream} datastream reports invalid VBR quality of {$mp3_field_quality} (expected: between 0-100)");
$this->addResult($assertion, $message);
}
}
}
}
}
// If none of that works out, fail.
// If none of that works out, fail.
else {
else {
$this->addFail( "{$this->datastream} datastream is corrupt and does not identify as a valid MP3.");
$this->addResult(FALSE, "{$this->datastream} datastream is corrupt and does not identify as a valid MP3.");
}
}
}
}
@ -660,13 +678,12 @@ class MP4DatastreamValidator extends DatastreamValidator {
* Asserts that the datastream is ISO-formatted video.
* Asserts that the datastream is ISO-formatted video.
*/
*/
protected function assertISOVideo() {
protected function assertISOVideo() {
if (strpos($this->datastreamContent, 'ftyp')) {
$mp4_ftyp = substr(strpos($this->datastreamContent, 'ftyp'), 4, 4);
$mp4_ftyp = substr(strpos($this->datastreamContent, 'ftyp'), 4, 4);
$assertion = strpos($this->datastreamContent, 'ftyp') !== 0;
$this->addPass("{$this->datastream} datastream asserts that it is a valid ISO-formatted video file using ftyp {$mp4_ftyp}");
$pass = "{$this->datastream} datastream asserts that it is a valid ISO-formatted video file using ftyp {$mp4_ftyp}";
}
$fail = "{$this->datastream} datastream is not a valid ISO-formatted video";
else {
$message = $assertion ? $pass : $fail;
$this->addFail("{$this->datastream} datastream is not a valid ISO-formatted video");
$this->addResult($assertion, $message);
}
}
}
}
}
@ -686,36 +703,33 @@ class OGGDatastreamValidator extends DatastreamValidator {
*/
*/
protected function assertOGGPages() {
protected function assertOGGPages() {
$ogg_pages = substr_count($this->datastreamContent, 'OggS');
$ogg_pages = substr_count($this->datastreamContent, 'OggS');
if ($ogg_pages !== 0) {
$assertion = $ogg_pages !== 0;
$this->addPass("{$this->datastream} datastream asserts that it contains {$ogg_pages} Ogg pages (even a very small file should contain several).");
$pass = "{$this->datastream} datastream asserts that it contains {$ogg_pages} Ogg pages (even a very small file should contain several).";
}
$fail = "{$this->datastream} datastream contains no Ogg pages.";
else {
$message = $assertion ? $pass : $fail;
$this->addFail("{$this->datastream} datastream contains no Ogg pages.");
$this->addResult($assertion, $message);
}
}
}
/**
/**
* Asserts that the datastream contains Theora-encoded video.
* Asserts that the datastream contains Theora-encoded video.
*/
*/
protected function assertTheoraVideo() {
protected function assertTheoraVideo() {
if (substr_count($this->datastreamContent, 'theora') !== 0) {
$assertion = substr_count($this->datastreamContent, 'theora') !== 0;
$this->addPass("{$this->datastream} datastream asserts that it contains Theora-encoded video data.");
$pass = "{$this->datastream} datastream asserts that it contains Theora-encoded video data.";
}
$fail = "{$this->datastream} datastream contains no marker indicating the presence of Theora-encoded video data.";
else {
$message = $assertion ? $pass : $fail;
$this->addFail("{$this->datastream} datastream contains no marker indicating the presence of Theora-encoded video data.");
$this->addResult($assertion, $message);
}
}
}
/**
/**
* Asserts that the datastream contains Vorbis-encoded audio.
* Asserts that the datastream contains Vorbis-encoded audio.
*/
*/
protected function assertVorbisAudio() {
protected function assertVorbisAudio() {
if (substr_count($this->datastreamContent, 'vorbis')) {
$assertion = substr_count($this->datastreamContent, 'vorbis') !== 0;
$this->addPass("{$this->datastream} datastream asserts that it contains Vorbis-encoded audio data");
$pass = "{$this->datastream} datastream asserts that it contains Vorbis-encoded audio data";
}
$fail = "{$this->datastream} datastream contains no marker indicating the presence of Vorbis-encoded audio data.";
else {
$message = $assertion ? $pass : $fail;
$this->addFail("{$this->datastream} datastream contains no marker indicating the presence of Vorbis-encoded audio data.");
$this->addResult($assertion, $message);
}
}
}
}
}
@ -735,23 +749,21 @@ class MKVDatastreamValidator extends DatastreamValidator {
* Asserts that the datastream is an EBML-format file.
* Asserts that the datastream is an EBML-format file.
*/
*/
protected function assertEBMLFormat() {
protected function assertEBMLFormat() {
if (substr(bin2hex($this->datastreamContent), 0, 8) == '1a45dfa3') {
$assertion = substr(bin2hex($this->datastreamContent), 0, 8) == '1a45dfa3';
$this->addPass("{$this->datastream} datastream asserts that it is an EBML-formatted file");
$pass = "{$this->datastream} datastream asserts that it is an EBML-formatted file";
}
$fail = "{$this->datastream} datastream is not an EBML-formatted file.";
else {
$message = $assertion ? $pass : $fail;
$this->addFail("{$this->datastream} datastream is not an EBML-formatted file.");
$this->addResult($assertion, $message);
}
}
}
/**
/**
* Asserts that the datastream contains a matroska marker.
* Asserts that the datastream contains a matroska marker.
*/
*/
protected function assertMatroskaMarker() {
protected function assertMatroskaMarker() {
if (substr_count($this->datastreamContent, 'matroska') == 1) {
$assertion = substr_count($this->datastreamContent, 'matroska') == 1;
$this->addPass("{$this->datastream} datastream asserts that its EBML DocType is Matroska");
$pass = "{$this->datastream} datastream asserts that its EBML DocType is Matroska";
}
$fail = "{$this->datastream} datastream does not contain a Matroska EBML DocType marker.";
else {
$message = $assertion ? $pass : $fail;
$this->addFail("{$this->datastream} datastream does not contain a Matroska EBML DocType marker.");
$this->addResult($assertion, $message);
}
}
}
}
}