Update preview image generation. Update unit tests.
authorMichael Ang <mang@archive.org>
Wed, 28 Apr 2010 22:16:06 +0000 (22:16 +0000)
committerMichael Ang <mang@archive.org>
Wed, 28 Apr 2010 22:16:06 +0000 (22:16 +0000)
BookReaderIA/datanode/BookReaderImages.inc.php
BookReaderIA/datanode/BookReaderImages.php
BookReaderIA/datanode/BookReaderMeta.inc.php
BookReaderIA/datanode/BookReaderPreview.php
BookReaderIA/test/index.html
BookReaderIA/test/unit/Common.js [new file with mode: 0644]
BookReaderIA/test/unit/Images.js
BookReaderIA/test/unit/JSLocate.js
BookReaderIA/test/unit/Preview.js [new file with mode: 0644]
BookReaderIA/test/unit/Search.js

index 5af62e1..5662a86 100644 (file)
@@ -530,8 +530,9 @@ class BookReaderImages
     }
     
     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
index 1af5864..a3d2517 100644 (file)
@@ -29,7 +29,17 @@ require_once('BookReaderImages.inc.php');
 
 // 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();
+}
 
 ?>
 
index e1b4ff3..a68c4b9 100644 (file)
@@ -221,8 +221,9 @@ class BookReaderMeta {
     
     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
index 5fb4a7f..8770a9c 100644 (file)
@@ -28,12 +28,17 @@ require_once('BookReaderImages.inc.php');
 
 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'];
@@ -85,11 +90,20 @@ $requestEnv = array(
     '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
index eccdcbb..b17eff8 100644 (file)
@@ -5,9 +5,11 @@
   <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>
diff --git a/BookReaderIA/test/unit/Common.js b/BookReaderIA/test/unit/Common.js
new file mode 100644 (file)
index 0000000..c435937
--- /dev/null
@@ -0,0 +1,30 @@
+// 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
index e2fabb9..0427def 100644 (file)
@@ -1,30 +1,10 @@
 // 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);
@@ -48,8 +28,7 @@ asyncTest("Image info for jpeg", function() {
         start();
     });
 });
-
-
+*/
 
 // Test image info
 asyncTest("JSLocate for zc-f-c-b-4 - 1-bit jp2", function() {
index 17136c7..148b19f 100644 (file)
@@ -1,24 +1,9 @@
 // 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'),
diff --git a/BookReaderIA/test/unit/Preview.js b/BookReaderIA/test/unit/Preview.js
new file mode 100644 (file)
index 0000000..3a34306
--- /dev/null
@@ -0,0 +1,59 @@
+// 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
index bf05a54..6ca6eb0 100644 (file)
@@ -1,32 +1,12 @@
 // 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
@@ -50,14 +30,6 @@ function setSearchText(txtData) {
     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);