Browse Source

Image test refactoring

v1.x
Tj Holowaychuk 14 years ago
parent
commit
3a5c0d8ada
  1. 4
      src/Image.cc
  2. 10
      test/image.test.js

4
src/Image.cc

@ -197,6 +197,7 @@ Image::load() {
void void
Image::loadSync() { Image::loadSync() {
HandleScope scope;
TryCatch try_catch; TryCatch try_catch;
loadSurface(); loadSurface();
if (try_catch.HasCaught()) { if (try_catch.HasCaught()) {
@ -256,6 +257,7 @@ Image::error(TryCatch &try_catch) {
Handle<Value> Handle<Value>
Image::loadSurface() { Image::loadSurface() {
HandleScope scope;
switch (extension(filename)) { switch (extension(filename)) {
case Image::PNG: return loadPNG(); case Image::PNG: return loadPNG();
#ifdef HAVE_JPEG #ifdef HAVE_JPEG
@ -271,6 +273,7 @@ Image::loadSurface() {
Handle<Value> Handle<Value>
Image::loadPNG() { Image::loadPNG() {
HandleScope scope;
_surface = cairo_image_surface_create_from_png(filename); _surface = cairo_image_surface_create_from_png(filename);
cairo_status_t status = cairo_surface_status(_surface); cairo_status_t status = cairo_surface_status(_surface);
if (status) { if (status) {
@ -290,6 +293,7 @@ Image::loadPNG() {
Handle<Value> Handle<Value>
Image::loadJPEG() { Image::loadJPEG() {
HandleScope scope;
FILE *stream = fopen(filename, "r"); FILE *stream = fopen(filename, "r");
// Generalized errors // Generalized errors

10
test/image.test.js

@ -37,6 +37,7 @@ module.exports = {
'test Image#onerror': function(assert, beforeExit){ 'test Image#onerror': function(assert, beforeExit){
var img = new Image var img = new Image
, error
, n = 0; , n = 0;
assert.strictEqual(false, img.complete); assert.strictEqual(false, img.complete);
@ -46,19 +47,20 @@ module.exports = {
img.onerror = function(err){ img.onerror = function(err){
++n; ++n;
assert.strictEqual(false, img.complete); error = err;
assert.ok(err instanceof Error, 'did not invoke onerror() with error');
}; };
try { try {
img.src = png + 's'; img.src = png + 's';
} catch (err) { } catch (err) {
assert.fail('got error ' + err); assert.fail('error did not invoke onerror(): ' + err);
} }
assert.equal(img.src, png + 's'); assert.equal(img.src, png + 's');
beforeExit(function(){ beforeExit(function(){
assert.ok(error instanceof Error, 'did not invoke onerror() with error');
assert.strictEqual(false, img.complete);
assert.equal(1, n); assert.equal(1, n);
}); });
}, },

Loading…
Cancel
Save