}
function BRfatal($string) {
- echo "alert('$string');\n";
- die(-1);
+ throw new Exception("Image error: $string");
+ //echo "alert('$string');\n";
+ //die(-1);
}
// Returns true if using a power node
// Serve request
$bri = new BookReaderImages();
-$bri->serveRequest($_REQUEST);
+try {
+ $bri->serveRequest($_REQUEST);
+} catch (Exception $e) {
+ header("HTTP/1.0 404 Not Found");
+ header("Content-type: text/plain");
+
+ print "Error serving request:\n";
+ print " " . $e->getMessage() . "\n\n";
+ print "Debugging information:\n";
+ echo $e->getTraceAsString();
+}
?>
function BRFatal($string) {
// $$$ TODO log error
- echo "alert('$string');\n";
- die(-1);
+ throw new Exception("Metadata error: $string");
+ //echo "alert('$string');\n";
+ //die(-1);
}
// Returns true if a page should be added based on it's information in
function BRfatal($message) {
header("HTTP/1.0 404 Not Found");
+ header("Content-type: text/plain");
print $message;
- exit();
+ die(-1);
}
$brm = new BookReaderMeta();
-$metadata = $brm->buildMetadata($_REQUEST['id'], $_REQUEST['itemPath'], $_REQUEST['bookId'], $_REQUEST['server']);
+try {
+ $metadata = $brm->buildMetadata($_REQUEST['id'], $_REQUEST['itemPath'], $_REQUEST['bookId'], $_REQUEST['server']);
+} catch (Exception $e) {
+ BRfatal($e->getMessage);
+}
$knownPages = array('title','cover','preview');
$page = $_REQUEST['page'];
'zip' => $metadata['zip'],
'file' => $brm->imageFilePath($leaf, $metadata['bookId'], $metadata['imageFormat']),
'ext' => 'jpg',
- 'reduce' => 2, // XXX
);
// Return image data - will check privs
$bri = new BookReaderImages();
-$bri->serveRequest($requestEnv);
+try {
+ $bri->serveRequest($requestEnv);
+} catch (Exception $e) {
+ header("HTTP/1.0 404 Not Found");
+ header("Content-type: text/plain");
+ print "Error serving request:";
+ print " " . $e->getMessage();
+ print "Debugging information:";
+ echo $e->getTraceAsString();
+ die(-1);
+}
?>
\ No newline at end of file
<script src="http://code.jquery.com/jquery-latest.js"></script>
<link rel="stylesheet" href="http://www.archive.org/download/BookReader/css/qunit.css" type="text/css" media="screen" />
<script type="text/javascript" src="http://www.archive.org/download/BookReader/lib/qunit.js"></script>
+ <script type="text/javascript" src="unit/Common.js"></script>
<script type="text/javascript" src="unit/JSLocate.js"></script>
<script type="text/javascript" src="unit/Images.js"></script>
<script type="text/javascript" src="unit/Search.js"></script>
+ <script type="text/javascript" src="unit/Preview.js"></script>
</head>
<body>
--- /dev/null
+// Defines common variables for testing
+// TODO - don't use global namespace
+
+// $$$ TODO make test host auto-magic
+common = {
+ testHost: 'http://www-testflip.archive.org'
+ // testHost: 'http://www-mang.archive.org'
+}
+
+// Set up dummy BookReader class for JSLocate
+function BookReader() {
+};
+
+BookReader.prototype.init = function() {
+ return true;
+};
+
+
+// Returns locator URL for the given id
+function jsLocateURL(identifier, book) {
+ var bookURL = common.testHost + '/bookreader/BookReaderJSLocate.php?id=' + identifier;
+ if (book) {
+ bookURL += '&book=' + book;
+ }
+ return bookURL;
+}
+
+function previewURL(identifier, bookId, page) {
+ return common.testHost + '/download/' + identifier + '/page/' + bookId + '_' + page + '.jpg';
+}
\ No newline at end of file
// Tests for BookReaderImages.php
-// $$$ TODO -- make the test host configurable/automagic
+// Depends on common.js
module("Images");
-// $$$ set to test host
-var testHost = 'http://www-testflip.archive.org';
-
-// Returns locator URL for the given id
-function jsLocateURL(identifier, book) {
- var bookURL = testHost + '/bookreader/BookReaderJSLocate.php?id=' + identifier;
- if (book) {
- bookURL += '&book=' + book;
- }
- return bookURL;
-}
-
-// Set up dummy BookReader class for JSLocate
-function BookReader() {
-};
-
-BookReader.prototype.init = function() {
- return true;
-};
-
-
+/* Item no longer available
// Test image info - jpeg
asyncTest("JSLocate for armageddonafter00couruoft - jpeg", function() {
expect(1);
start();
});
});
-
-
+*/
// Test image info
asyncTest("JSLocate for zc-f-c-b-4 - 1-bit jp2", function() {
// Tests for BookReaderJSLocate.php
-// $$$ TODO -- make the test host configurable/automagic
+// Depends on common.js
module("JSLocate");
-testHost = 'http://www-testflip.archive.org';
-
-// Returns locator URL for the given id
-function jsLocateURL(bookId) {
- return testHost + '/bookreader/BookReaderJSLocate.php?id=' + bookId;
-}
-
-// Set up dummy BookReader class for JSLocate
-function BookReader() {
-};
-
-BookReader.prototype.init = function() {
- return true;
-};
-
asyncTest("JSLocate for notesonsubmarine00grea", function() {
expect(1);
$.getScript( jsLocateURL('notesonsubmarine00grea'),
--- /dev/null
+// Tests for BookReaderPreview.php
+
+// Depends on common.js
+
+module("Preview");
+
+var identifiers = [
+ 'coloritsapplicat00andriala',
+ 'lietuvostsrmoksl50liet',
+ 'oldtestamentrevi02slsn',
+ 'bokeofsaintalban00bernuoft'
+];
+
+for (index in identifiers) {
+ var identifier = identifiers[index];
+ asyncTest("Load preview for " + identifier, function() {
+ expect(1);
+
+ var pageURI = previewURL(identifier, identifier, 'preview');
+ var img = new Image();
+ $(img).bind( 'load error', function(eventObj) {
+ equals(eventObj.type, 'load', 'Load image (' + pageURI + '). Event handler called');
+ start();
+ })
+ .attr('src', pageURI);
+
+ img = null;
+ });
+
+ asyncTest("Load cover for " + identifier, function() {
+ expect(1);
+
+ var pageURI = previewURL(identifier, identifier, 'cover');
+ var img = new Image();
+ $(img).bind( 'load error', function(eventObj) {
+ equals(eventObj.type, 'load', 'Load image (' + pageURI + '). Event handler called');
+ start();
+ })
+ .attr('src', pageURI);
+
+ img = null;
+ });
+
+ asyncTest("Load title for " + identifier, function() {
+ expect(1);
+
+ var pageURI = previewURL(identifier, identifier, 'title');
+ var img = new Image();
+ $(img).bind( 'load error', function(eventObj) {
+ equals(eventObj.type, 'load', 'Load image (' + pageURI + '). Event handler called');
+ start();
+ })
+ .attr('src', pageURI);
+
+ img = null;
+ });
+
+
+}
\ No newline at end of file
// Tests for Search
-// $$$ TODO -- make the test host configurable/automagic
-// $$$ Refactor common code across tests
+// Depends on common.js
module("Search");
-// $$$ set to test host
-var gTestAccount = 'testflip';
-//var gTestAccount = 'mang';
-var gTestHost = 'http://www-' + gTestAccount + '.archive.org';
-
// Holds search text
var gSearchText = '';
-test("Hello test", function() {
- expect(1);
- equals("Hello world", "Hello world", "Hi there");
-});
-
-// Returns locator URL for the given id
-function jsLocateURL(identifier, book) {
- var bookURL = gTestHost + '/bookreader/BookReaderJSLocate.php?id=' + identifier;
- if (book) {
- bookURL += '&book=' + book;
- }
- return bookURL;
-}
-
// Build search URL
function searchURL(bookReader, term, callback) {
var url = 'http://' + bookReader.server
gSearchText = txtData;
}
-// Set up dummy BookReader class for JSLocate
-function BookReader() {
-};
-
-BookReader.prototype.init = function() {
- return true;
-};
-
function locateTest(title, identifier, book) {
asyncTest("JSLocate for " + identifier, function() {
expect(2);