Unit tests for proportional "within width/height" scaling
[bookreader.git] / BookReaderIA / test / unit / Images.js
index 1f48ef0..40b928d 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-mang.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() {
@@ -106,6 +85,46 @@ asyncTest("Load windwavesatseabr00bige image 5", function() {
 });
 
 
+/// nybc200109 - 1-bit tiff zip
+asyncTest("JSLocate for nybc200109 - 1-bit tiff.zip book", function() {
+    expect(1);
+    $.getScript( jsLocateURL('nybc200109'), function() {
+        equals(br.numLeafs,
+               694,
+               'Number of pages');
+        start();
+    });
+});
+
+asyncTest("Image info for 1-bit tiff", function() {
+    expect(3);
+    var expected = {"width":5081,"height":6592,"bits":1,"type":"tiff"};
+    var imageInfoURL = br.getPageURI(0) + '&ext=json&callback=?';
+    
+    $.getJSON(imageInfoURL, function(data) {
+        equals(data != null, true, 'data is not null');
+        if (data != null) {
+            equals(data.width, expected.width, 'Image width');
+            same(data, expected, 'Image info object');
+        }
+        start();
+    });
+});
+
+asyncTest("Load 1-bit tiff image from zip", function() {
+    expect(2);
+    var pageURI = br.getPageURI(6, 16);
+    var img = new Image();
+    $(img).bind( 'load error', function(eventObj) {
+        equals(eventObj.type, 'load', 'Load image (' + pageURI + '). Event handler called');
+        equals(this.width, 1272, 'Image width');
+        start();
+    })
+    .attr('src', pageURI);
+});
+
+
+
 /// asamoandictiona00pragoog - tiff zip
 asyncTest("JSLocate for asamoandictiona00pragoog - tiff.zip book", function() {
     expect(1);
@@ -117,13 +136,28 @@ asyncTest("JSLocate for asamoandictiona00pragoog - tiff.zip book", function() {
     });
 });
 
+asyncTest("Image info for 8-bit tiff", function() {
+    expect(3);
+    var expected = {"width":1275,"height":1650,"bits":8,"type":"tiff"};
+    var imageInfoURL = br.getPageURI(0) + '&ext=json&callback=?';
+    
+    $.getJSON(imageInfoURL, function(data) {
+        equals(data != null, true, 'data is not null');
+        if (data != null) {
+            equals(data.width, expected.width, 'Image width');
+            same(data, expected, 'Image info object');
+        }
+        start();
+    });
+});
+
 asyncTest("Load tiff image from zip", function() {
     expect(2);
     var pageURI = br.getPageURI(23, 8);
     var img = new Image();
     $(img).bind( 'load error', function(eventObj) {
         equals(eventObj.type, 'load', 'Load image (' + pageURI + '). Event handler called');
-        equals(this.width, 351, 'Image width');
+        equals(this.width, 701, 'Image width');
         start();
     })
     .attr('src', pageURI);
@@ -145,9 +179,124 @@ asyncTest('Load jpg image from tar file - https://bugs.launchpad.net/bookreader/
     var img = new Image();
     $(img).bind( 'load error', function(eventObj) {
         equals(eventObj.type, 'load', 'Load image (' + pageURI + '). Event handler called');
-        equals(this.width, 244, 'Image width');
+        equals(this.width, 243, 'Image width');
         start();
     })
     .attr('src', pageURI);
 });
 
+asyncTest('Load image region - /download/populationsc18400378unit/page/n800_x1544_y4144_w1192_h848_s4.jpg', function() {
+    expect(3);
+    var pageURI = testHost() + '/download/populationsc18400378unit/page/n800_x1544_y4144_w1192_h848_s4.jpg';
+    
+    var img = new Image();
+    $(img).bind( 'load error', function(eventObj) {
+        equals(eventObj.type, 'load', 'Load image (' + pageURI + '). Event handler called');
+        equals(this.width, 299, 'Image width');
+        equals(this.height, 212, 'Image height');
+        start();
+    })
+    .attr('src', pageURI);    
+
+});
+
+asyncTest('Load image region using decimal coordinates - /download/populationsc18400378unit/page/n800_x0.75_y0.75_w0.25_h0.25_s4.jpg', function() {
+    expect(3);
+    var pageURI = testHost() + '/download/populationsc18400378unit/page/n800_x0.75_y0.75_w0.25_h0.25_s4.jpg';
+    
+    var img = new Image();
+    $(img).bind( 'load error', function(eventObj) {
+        equals(eventObj.type, 'load', 'Load image (' + pageURI + '). Event handler called');
+        equals(this.width, 337, 'Image width');
+        equals(this.height, 342, 'Image height');
+        start();
+    })
+    .attr('src', pageURI);    
+
+});
+
+
+asyncTest('Load image region - /download/tomslademotorcyc00fitz/page/page3_x256_y96_w1720_h152_s4.jpg', function() {
+    expect(3);
+    var pageURI = testHost() + '/download/tomslademotorcyc00fitz/page/page3_x256_y96_w1720_h152_s4.jpg';
+    
+    var img = new Image();
+    $(img).bind( 'load error', function(eventObj) {
+        equals(eventObj.type, 'load', 'Load image (' + pageURI + '). Event handler called');
+        equals(this.width, 430, 'Image width');
+        equals(this.height, 38, 'Image height');
+        start();
+    })
+    .attr('src', pageURI);    
+
+});
+
+asyncTest('Load cover, fitting within 400x400', function() {
+    expect(3);
+    var pageURI = testHost() + '/download/mechanicstheor00loverich/page/cover_w400_h400.jpg';
+    
+    var img = new Image();
+    $(img).bind( 'load error', function(eventObj) {
+        equals(eventObj.type, 'load', 'Load image (' + pageURI + '). Event handler called');
+        equals(this.width, 264, 'Image width');
+        equals(this.height, 487, 'Image height');
+        start();
+    })
+    .attr('src', pageURI);    
+
+});
+
+asyncTest('Load cover, fitting within 100x400', function() {
+    expect(3);
+    var pageURI = testHost() + '/download/mechanicstheor00loverich/page/cover_w100_h400.jpg';
+    
+    var img = new Image();
+    $(img).bind( 'load error', function(eventObj) {
+        equals(eventObj.type, 'load', 'Load image (' + pageURI + '). Event handler called');
+        equals(this.width, 132, 'Image width');
+        equals(this.height, 244, 'Image height');
+        start();
+    })
+    .attr('src', pageURI);    
+
+});
+
+
+asyncTest('Load image region from tiff, via br.getRegionURI - fightingflyingc00rickgoog - n17_x1944_y1708_w668_h584', function() {
+
+    $.getScript( jsLocateURL('fightingflyingc00rickgoog'), function() {
+
+        expect(3);
+        var pageURI = br.getRegionURI(17, undefined, undefined, 1944, 1708, 668, 584);
+        
+        var img = new Image();
+        $(img).bind( 'load error', function(eventObj) {
+            equals(eventObj.type, 'load', 'Load image (' + pageURI + '). Event handler called');
+            equals(this.width, 668, 'Image width');
+            equals(this.height, 584, 'Image height');
+            start();
+        })
+        .attr('src', pageURI);
+        
+    });
+});
+
+asyncTest('Same image rotated 90 degrees, br.getRegionURI - fightingflyingc00rickgoog - n17_x1944_y1708_w668_h584_rot90', function() {
+
+    $.getScript( jsLocateURL('fightingflyingc00rickgoog'), function() {
+
+        expect(3);
+        var pageURI = br.getRegionURI(17, undefined, 90, 1944, 1708, 668, 584);
+        
+        var img = new Image();
+        $(img).bind( 'load error', function(eventObj) {
+            equals(eventObj.type, 'load', 'Load image (' + pageURI + '). Event handler called');
+            equals(this.width, 584, 'Image width');
+            equals(this.height, 668, 'Image height');
+            start();
+        })
+        .attr('src', pageURI);
+        
+    });
+});
+