Update unit tests
[bookreader.git] / BookReaderIA / test / unit / Images.js
1 // Tests for BookReaderImages.php
2
3 // Depends on common.js
4
5 module("Images");
6
7 /* Item no longer available
8 // Test image info - jpeg
9 asyncTest("JSLocate for armageddonafter00couruoft - jpeg", function() {
10     expect(1);
11     $.getScript( jsLocateURL('armageddonafter00couruoft'), function() {
12         equals(br.bookTitle, 'Armageddon and after', 'Title');
13         start();
14     });
15 });
16
17 asyncTest("Image info for jpeg", function() {
18     expect(3);
19     var expected = {"width":1349,"height":2105,"bits":8,"type":"jpeg"};
20     var imageInfoURL = br.getPageURI(8) + '&ext=json&callback=?';
21     
22     $.getJSON(imageInfoURL, function(data) {
23         equals(data != null, true, 'data is not null');
24         if (data != null) {
25             equals(data.width, expected.width, 'Image width');
26             same(data, expected, 'Image info object');
27         }
28         start();
29     });
30 });
31 */
32
33 // Test image info
34 asyncTest("JSLocate for zc-f-c-b-4 - 1-bit jp2", function() {
35     expect(1);
36     $.getScript( jsLocateURL('zc-f-c-b-4', 'concept-of-infection'), function() {
37         equals(br.numLeafs, 13, 'numLeafs');
38         start();
39     });
40 });
41
42 asyncTest("Image info for 1-bit jp2", function() {
43     expect(3);
44     var expected = {"width":3295,"height":2561,"bits":1,"type":"jp2"};
45     var imageInfoURL = br.getPageURI(0) + '&ext=json&callback=?';
46     
47     $.getJSON(imageInfoURL, function(data) {
48         equals(data != null, true, 'data is not null');
49         if (data != null) {
50             equals(data.width, expected.width, 'Image width');
51             same(data, expected, 'Image info object');
52         }
53         start();
54     });
55 });
56
57 /// windwavesatseabr00bige - jp2 zip
58 asyncTest("JSLocate for windwavesatseabr00bige - Scribe jp2.zip book", function() {
59     expect(1);
60     $.getScript( jsLocateURL('windwavesatseabr00bige'), function(data, textStatus) {
61         equals(br.numLeafs, 224, 'JSLocate successful. numLeafs');
62         start();
63     });
64 });
65     
66 test("Image URI for windwavesatseabr00bige page index 5", function() {
67     expect(1);
68     var index = 5;
69     var expectedEnding = "file=windwavesatseabr00bige_jp2/windwavesatseabr00bige_0006.jp2&scale=1&rotate=0";
70     var pageURI = br.getPageURI(index);
71     var reg = new RegExp('file=.*$');
72     var actualEnding = reg.exec(pageURI);
73     equals(actualEnding, expectedEnding, 'URI for page index 5 ends with');
74 });
75
76 asyncTest("Load windwavesatseabr00bige image 5", function() {
77     var pageURI = br.getPageURI(5);
78     var img = new Image();
79     $(img).bind( 'load error', function(eventObj) {
80         equals(eventObj.type, 'load', 'Load image (' + pageURI + '). Event handler called');
81         start();
82     })
83     // Actually load the image
84     .attr('src', pageURI);
85 });
86
87
88 /// nybc200109 - 1-bit tiff zip
89 asyncTest("JSLocate for nybc200109 - 1-bit tiff.zip book", function() {
90     expect(1);
91     $.getScript( jsLocateURL('nybc200109'), function() {
92         equals(br.numLeafs,
93                694,
94                'Number of pages');
95         start();
96     });
97 });
98
99 asyncTest("Image info for 1-bit tiff", function() {
100     expect(3);
101     var expected = {"width":5081,"height":6592,"bits":1,"type":"tiff"};
102     var imageInfoURL = br.getPageURI(0) + '&ext=json&callback=?';
103     
104     $.getJSON(imageInfoURL, function(data) {
105         equals(data != null, true, 'data is not null');
106         if (data != null) {
107             equals(data.width, expected.width, 'Image width');
108             same(data, expected, 'Image info object');
109         }
110         start();
111     });
112 });
113
114 asyncTest("Load 1-bit tiff image from zip", function() {
115     expect(2);
116     var pageURI = br.getPageURI(6, 16);
117     var img = new Image();
118     $(img).bind( 'load error', function(eventObj) {
119         equals(eventObj.type, 'load', 'Load image (' + pageURI + '). Event handler called');
120         equals(this.width, 1272, 'Image width');
121         start();
122     })
123     .attr('src', pageURI);
124 });
125
126
127
128 /// asamoandictiona00pragoog - tiff zip
129 asyncTest("JSLocate for asamoandictiona00pragoog - tiff.zip book", function() {
130     expect(1);
131     $.getScript( jsLocateURL('asamoandictiona00pragoog'), function() {
132         equals(br.bookTitle,
133                'A Samoan dictionary: English and Samoan, and Samoan and English;',
134                'Book title');
135         start();
136     });
137 });
138
139 asyncTest("Image info for 8-bit tiff", function() {
140     expect(3);
141     var expected = {"width":1275,"height":1650,"bits":8,"type":"tiff"};
142     var imageInfoURL = br.getPageURI(0) + '&ext=json&callback=?';
143     
144     $.getJSON(imageInfoURL, function(data) {
145         equals(data != null, true, 'data is not null');
146         if (data != null) {
147             equals(data.width, expected.width, 'Image width');
148             same(data, expected, 'Image info object');
149         }
150         start();
151     });
152 });
153
154 asyncTest("Load tiff image from zip", function() {
155     expect(2);
156     var pageURI = br.getPageURI(23, 8);
157     var img = new Image();
158     $(img).bind( 'load error', function(eventObj) {
159         equals(eventObj.type, 'load', 'Load image (' + pageURI + '). Event handler called');
160         equals(this.width, 701, 'Image width');
161         start();
162     })
163     .attr('src', pageURI);
164 });
165
166
167 /// hccapp56191900uoft - jpeg tar
168 asyncTest("JSLocate for hccapp56191900uoft - jpg.tar", function() {
169     expect(1);
170     $.getScript( jsLocateURL('hccapp56191900uoft'), function() {
171         equals(br.numLeafs, 1101, 'Number of pages');
172         start();
173     });
174 });
175
176 asyncTest('Load jpg image from tar file - https://bugs.launchpad.net/bookreader/+bug/323003', function() {
177     expect(2);
178     var pageURI = br.getPageURI(6, 8);
179     var img = new Image();
180     $(img).bind( 'load error', function(eventObj) {
181         equals(eventObj.type, 'load', 'Load image (' + pageURI + '). Event handler called');
182         equals(this.width, 243, 'Image width');
183         start();
184     })
185     .attr('src', pageURI);
186 });
187
188 asyncTest('Load image region from tiff - archive.org/download/fightingflyingc00rickgoog/page/n17_x1944_y1708_w668_h584.jpg', function() {
189
190     $.getScript( jsLocateURL('fightingflyingc00rickgoog'), function() {
191
192         expect(3);
193         var pageURI = br.getRegionURI(17, undefined, undefined, 1944, 1708, 668, 584);
194         
195         var img = new Image();
196         $(img).bind( 'load error', function(eventObj) {
197             equals(eventObj.type, 'load', 'Load image (' + pageURI + '). Event handler called');
198             equals(this.width, 668, 'Image width');
199             equals(this.height, 584, 'Image height');
200             start();
201         })
202         .attr('src', pageURI);
203         
204     });
205 });