Skip to content

Commit

Permalink
Image test refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
tj committed Mar 14, 2011
1 parent bef75cc commit 3a5c0d8
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
4 changes: 4 additions & 0 deletions src/Image.cc
Expand Up @@ -197,6 +197,7 @@ Image::load() {

void
Image::loadSync() {
HandleScope scope;
TryCatch try_catch;
loadSurface();
if (try_catch.HasCaught()) {
Expand Down Expand Up @@ -256,6 +257,7 @@ Image::error(TryCatch &try_catch) {

Handle<Value>
Image::loadSurface() {
HandleScope scope;
switch (extension(filename)) {
case Image::PNG: return loadPNG();
#ifdef HAVE_JPEG
Expand All @@ -271,6 +273,7 @@ Image::loadSurface() {

Handle<Value>
Image::loadPNG() {
HandleScope scope;
_surface = cairo_image_surface_create_from_png(filename);
cairo_status_t status = cairo_surface_status(_surface);
if (status) {
Expand All @@ -290,6 +293,7 @@ Image::loadPNG() {

Handle<Value>
Image::loadJPEG() {
HandleScope scope;
FILE *stream = fopen(filename, "r");

// Generalized errors
Expand Down
10 changes: 6 additions & 4 deletions test/image.test.js
Expand Up @@ -37,6 +37,7 @@ module.exports = {

'test Image#onerror': function(assert, beforeExit){
var img = new Image
, error
, n = 0;

assert.strictEqual(false, img.complete);
Expand All @@ -46,19 +47,20 @@ module.exports = {

img.onerror = function(err){
++n;
assert.strictEqual(false, img.complete);
assert.ok(err instanceof Error, 'did not invoke onerror() with error');
error = err;
};

try {
img.src = png + 's';
} catch (err) {
assert.fail('got error ' + err);
assert.fail('error did not invoke onerror(): ' + err);
}

assert.equal(img.src, png + 's');

beforeExit(function(){
assert.ok(error instanceof Error, 'did not invoke onerror() with error');
assert.strictEqual(false, img.complete);
assert.equal(1, n);
});
},
Expand Down

0 comments on commit 3a5c0d8

Please sign in to comment.